/[jscoverage]/trunk/js/jshash.cpp
ViewVC logotype

Diff of /trunk/js/jshash.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 332 by siliconforks, Thu Oct 23 19:03:33 2008 UTC revision 507 by siliconforks, Sun Jan 10 07:23:34 2010 UTC
# Line 1  Line 1 
1  /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-  /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2   *   *
3   * ***** BEGIN LICENSE BLOCK *****   * ***** BEGIN LICENSE BLOCK *****
4   * Version: MPL 1.1/GPL 2.0/LGPL 2.1   * Version: MPL 1.1/GPL 2.0/LGPL 2.1
# Line 40  Line 40 
40  /*  /*
41   * PR hash table package.   * PR hash table package.
42   */   */
 #include "jsstddef.h"  
43  #include <stdlib.h>  #include <stdlib.h>
44  #include <string.h>  #include <string.h>
45  #include "jstypes.h"  #include "jstypes.h"
46    #include "jsstdint.h"
47  #include "jsbit.h"  #include "jsbit.h"
48  #include "jsutil.h" /* Added by JSIFY */  #include "jsutil.h" /* Added by JSIFY */
49  #include "jshash.h" /* Added by JSIFY */  #include "jshash.h" /* Added by JSIFY */
# Line 71  Line 71 
71  }  }
72    
73  static void  static void
74  DefaultFreeTable(void *pool, void *item)  DefaultFreeTable(void *pool, void *item, size_t size)
75  {  {
76      free(item);      js_free(item);
77  }  }
78    
79  static JSHashEntry *  static JSHashEntry *
# Line 86  Line 86 
86  DefaultFreeEntry(void *pool, JSHashEntry *he, uintN flag)  DefaultFreeEntry(void *pool, JSHashEntry *he, uintN flag)
87  {  {
88      if (flag == HT_FREE_ENTRY)      if (flag == HT_FREE_ENTRY)
89          free(he);          js_free(he);
90  }  }
91    
92  static JSHashAllocOps defaultHashAllocOps = {  static JSHashAllocOps defaultHashAllocOps = {
# Line 121  Line 121 
121      nb = n * sizeof(JSHashEntry *);      nb = n * sizeof(JSHashEntry *);
122      ht->buckets = (JSHashEntry**) allocOps->allocTable(allocPriv, nb);      ht->buckets = (JSHashEntry**) allocOps->allocTable(allocPriv, nb);
123      if (!ht->buckets) {      if (!ht->buckets) {
124          allocOps->freeTable(allocPriv, ht);          allocOps->freeTable(allocPriv, ht, nb);
125          return NULL;          return NULL;
126      }      }
127      memset(ht->buckets, 0, nb);      memset(ht->buckets, 0, nb);
# Line 153  Line 153 
153  #ifdef DEBUG  #ifdef DEBUG
154      memset(ht->buckets, 0xDB, n * sizeof ht->buckets[0]);      memset(ht->buckets, 0xDB, n * sizeof ht->buckets[0]);
155  #endif  #endif
156      allocOps->freeTable(allocPriv, ht->buckets);      allocOps->freeTable(allocPriv, ht->buckets, n * sizeof ht->buckets[0]);
157  #ifdef DEBUG  #ifdef DEBUG
158      memset(ht, 0xDB, sizeof *ht);      memset(ht, 0xDB, sizeof *ht);
159  #endif  #endif
160      allocOps->freeTable(allocPriv, ht);      allocOps->freeTable(allocPriv, ht, sizeof *ht);
161  }  }
162    
163  /*  /*
# Line 198  Line 198 
198  {  {
199      size_t nb, nentries, i;      size_t nb, nentries, i;
200      JSHashEntry **oldbuckets, *he, *next, **hep;      JSHashEntry **oldbuckets, *he, *next, **hep;
 #ifdef DEBUG  
201      size_t nold = NBUCKETS(ht);      size_t nold = NBUCKETS(ht);
 #endif  
202    
203      JS_ASSERT(newshift < JS_HASH_BITS);      JS_ASSERT(newshift < JS_HASH_BITS);
204    
# Line 230  Line 228 
228              hep = BUCKET_HEAD(ht, he->keyHash);              hep = BUCKET_HEAD(ht, he->keyHash);
229    
230              /*              /*
231               * Since he comes from the old table, it must be unique and we               * We do not require unique entries, instead appending he to the
232               * simply add it to the head of bucket chain without chain lookup.               * chain starting at hep.
233               */               */
234              he->next = *hep;              while (*hep)
235                    hep = &(*hep)->next;
236                he->next = NULL;
237              *hep = he;              *hep = he;
238          }          }
239      }      }
240  #ifdef DEBUG  #ifdef DEBUG
241      memset(oldbuckets, 0xDB, nold * sizeof oldbuckets[0]);      memset(oldbuckets, 0xDB, nold * sizeof oldbuckets[0]);
242  #endif  #endif
243      ht->allocOps->freeTable(ht->allocPriv, oldbuckets);      ht->allocOps->freeTable(ht->allocPriv, oldbuckets,
244                                nold * sizeof oldbuckets[0]);
245      return JS_TRUE;      return JS_TRUE;
246  }  }
247    
248  JS_PUBLIC_API(JSHashEntry *)  JS_PUBLIC_API(JSHashEntry *)
249  JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **hep,  JS_HashTableRawAdd(JSHashTable *ht, JSHashEntry **&hep,
250                     JSHashNumber keyHash, const void *key, void *value)                     JSHashNumber keyHash, const void *key, void *value)
251  {  {
252      uint32 n;      uint32 n;

Legend:
Removed from v.332  
changed lines
  Added in v.507

  ViewVC Help
Powered by ViewVC 1.1.24