/src/nss/lib/base/hashops.c
Line | Count | Source |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | /* |
6 | | * hashops.c |
7 | | * |
8 | | * This file includes a set of PLHashAllocOps that use NSSArenas. |
9 | | */ |
10 | | |
11 | | #ifndef BASE_H |
12 | | #include "base.h" |
13 | | #endif /* BASE_H */ |
14 | | |
15 | | static void *PR_CALLBACK |
16 | | nss_arena_hash_alloc_table(void *pool, PRSize size) |
17 | 48 | { |
18 | 48 | NSSArena *arena = (NSSArena *)NULL; |
19 | | |
20 | | #ifdef NSSDEBUG |
21 | | if ((void *)NULL != arena) { |
22 | | if (PR_SUCCESS != nssArena_verifyPointer(arena)) { |
23 | | return (void *)NULL; |
24 | | } |
25 | | } |
26 | | #endif /* NSSDEBUG */ |
27 | | |
28 | 48 | return nss_ZAlloc(arena, size); |
29 | 48 | } |
30 | | |
31 | | static void PR_CALLBACK |
32 | | nss_arena_hash_free_table(void *pool, void *item) |
33 | 48 | { |
34 | 48 | (void)nss_ZFreeIf(item); |
35 | 48 | } |
36 | | |
37 | | static PLHashEntry *PR_CALLBACK |
38 | | nss_arena_hash_alloc_entry(void *pool, const void *key) |
39 | 92.9k | { |
40 | 92.9k | NSSArena *arena = NULL; |
41 | | |
42 | | #ifdef NSSDEBUG |
43 | | if ((void *)NULL != arena) { |
44 | | if (PR_SUCCESS != nssArena_verifyPointer(arena)) { |
45 | | return (void *)NULL; |
46 | | } |
47 | | } |
48 | | #endif /* NSSDEBUG */ |
49 | | |
50 | 92.9k | return nss_ZNEW(arena, PLHashEntry); |
51 | 92.9k | } |
52 | | |
53 | | static void PR_CALLBACK |
54 | | nss_arena_hash_free_entry(void *pool, PLHashEntry *he, PRUintn flag) |
55 | 92.9k | { |
56 | 92.9k | if (HT_FREE_ENTRY == flag) { |
57 | 92.9k | (void)nss_ZFreeIf(he); |
58 | 92.9k | } |
59 | 92.9k | } |
60 | | |
61 | | NSS_IMPLEMENT_DATA PLHashAllocOps nssArenaHashAllocOps = { |
62 | | nss_arena_hash_alloc_table, nss_arena_hash_free_table, |
63 | | nss_arena_hash_alloc_entry, nss_arena_hash_free_entry |
64 | | }; |