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

Diff of /trunk/js/jsdhash.cpp

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

revision 506 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  /* ***** BEGIN LICENSE BLOCK *****  /* ***** BEGIN LICENSE BLOCK *****
3   * Version: MPL 1.1/GPL 2.0/LGPL 2.1   * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4   *   *
# Line 44  Line 44 
44  #include <stdio.h>  #include <stdio.h>
45  #include <stdlib.h>  #include <stdlib.h>
46  #include <string.h>  #include <string.h>
47    #include "jsstdint.h"
48  #include "jsbit.h"  #include "jsbit.h"
49  #include "jsdhash.h"  #include "jsdhash.h"
50  #include "jsutil.h"     /* for JS_ASSERT */  #include "jsutil.h"     /* for JS_ASSERT */
# Line 71  Line 72 
72  #define RECURSION_LEVEL(table_) (*(uint32*)(table_->entryStore + \  #define RECURSION_LEVEL(table_) (*(uint32*)(table_->entryStore + \
73                                              JS_DHASH_TABLE_SIZE(table_) * \                                              JS_DHASH_TABLE_SIZE(table_) * \
74                                              table_->entrySize))                                              table_->entrySize))
75    /*
76     * Most callers that assert about the recursion level don't care about
77     * this magical value because they are asserting that mutation is
78     * allowed (and therefore the level is 0 or 1, depending on whether they
79     * incremented it).
80     *
81     * Only PL_DHashTableFinish needs to allow this special value.
82     */
83    #define IMMUTABLE_RECURSION_LEVEL ((uint32)-1)
84    
85    #define RECURSION_LEVEL_SAFE_TO_FINISH(table_)                                \
86        (RECURSION_LEVEL(table_) == 0 ||                                          \
87         RECURSION_LEVEL(table_) == IMMUTABLE_RECURSION_LEVEL)
88    
89  #define ENTRY_STORE_EXTRA                   sizeof(uint32)  #define ENTRY_STORE_EXTRA                   sizeof(uint32)
90  #define INCREMENT_RECURSION_LEVEL(table_)   \  #define INCREMENT_RECURSION_LEVEL(table_)                                     \
91      JS_BEGIN_MACRO                          \      JS_BEGIN_MACRO                                                            \
92        ++RECURSION_LEVEL(table_);            \          if (RECURSION_LEVEL(table_) != IMMUTABLE_RECURSION_LEVEL)             \
93                ++RECURSION_LEVEL(table_);                                        \
94      JS_END_MACRO      JS_END_MACRO
95  #define DECREMENT_RECURSION_LEVEL(table_)                  \  #define DECREMENT_RECURSION_LEVEL(table_)                                     \
96      JS_BEGIN_MACRO                                         \      JS_BEGIN_MACRO                                                            \
97        JSDHASH_ONELINE_ASSERT(RECURSION_LEVEL(table_) > 0); \          if (RECURSION_LEVEL(table_) != IMMUTABLE_RECURSION_LEVEL) {           \
98        --RECURSION_LEVEL(table_);                           \              JSDHASH_ONELINE_ASSERT(RECURSION_LEVEL(table_) > 0);              \
99                --RECURSION_LEVEL(table_);                                        \
100            }                                                                     \
101      JS_END_MACRO      JS_END_MACRO
102    
103  #else  #else
# Line 94  Line 111 
111  JS_PUBLIC_API(void *)  JS_PUBLIC_API(void *)
112  JS_DHashAllocTable(JSDHashTable *table, uint32 nbytes)  JS_DHashAllocTable(JSDHashTable *table, uint32 nbytes)
113  {  {
114      return malloc(nbytes);      return js_malloc(nbytes);
115  }  }
116    
117  JS_PUBLIC_API(void)  JS_PUBLIC_API(void)
118  JS_DHashFreeTable(JSDHashTable *table, void *ptr)  JS_DHashFreeTable(JSDHashTable *table, void *ptr)
119  {  {
120      free(ptr);      js_free(ptr);
121  }  }
122    
123  JS_PUBLIC_API(JSDHashNumber)  JS_PUBLIC_API(JSDHashNumber)
# Line 163  Line 180 
180  {  {
181      const JSDHashEntryStub *stub = (const JSDHashEntryStub *)entry;      const JSDHashEntryStub *stub = (const JSDHashEntryStub *)entry;
182    
183      free((void *) stub->key);      js_free((void *) stub->key);
184      memset(entry, 0, table->entrySize);      memset(entry, 0, table->entrySize);
185  }  }
186    
# Line 195  Line 212 
212  {  {
213      JSDHashTable *table;      JSDHashTable *table;
214    
215      table = (JSDHashTable *) malloc(sizeof *table);      table = (JSDHashTable *) js_malloc(sizeof *table);
216      if (!table)      if (!table)
217          return NULL;          return NULL;
218      if (!JS_DHashTableInit(table, ops, data, entrySize, capacity)) {      if (!JS_DHashTableInit(table, ops, data, entrySize, capacity)) {
219          free(table);          js_free(table);
220          return NULL;          return NULL;
221      }      }
222      return table;      return table;
# Line 209  Line 226 
226  JS_DHashTableDestroy(JSDHashTable *table)  JS_DHashTableDestroy(JSDHashTable *table)
227  {  {
228      JS_DHashTableFinish(table);      JS_DHashTableFinish(table);
229      free(table);      js_free(table);
230  }  }
231    
232  JS_PUBLIC_API(JSBool)  JS_PUBLIC_API(JSBool)
# Line 382  Line 399 
399      }      }
400    
401      DECREMENT_RECURSION_LEVEL(table);      DECREMENT_RECURSION_LEVEL(table);
402      JS_ASSERT(RECURSION_LEVEL(table) == 0);      JS_ASSERT(RECURSION_LEVEL_SAFE_TO_FINISH(table));
403    
404      /* Free entry storage last. */      /* Free entry storage last. */
405      table->ops->freeTable(table, table->entryStore);      table->ops->freeTable(table, table->entryStore);
# Line 688  Line 705 
705  {  {
706      JSDHashNumber keyHash;      /* load first in case clearEntry goofs it */      JSDHashNumber keyHash;      /* load first in case clearEntry goofs it */
707    
708        JS_ASSERT(RECURSION_LEVEL(table) != IMMUTABLE_RECURSION_LEVEL);
709    
710      JS_ASSERT(JS_DHASH_ENTRY_IS_LIVE(entry));      JS_ASSERT(JS_DHASH_ENTRY_IS_LIVE(entry));
711      keyHash = entry->keyHash;      keyHash = entry->keyHash;
712      table->ops->clearEntry(table, entry);      table->ops->clearEntry(table, entry);
# Line 763  Line 782 
782      return i;      return i;
783  }  }
784    
785    #ifdef DEBUG
786    JS_PUBLIC_API(void)
787    JS_DHashMarkTableImmutable(JSDHashTable *table)
788    {
789        RECURSION_LEVEL(table) = IMMUTABLE_RECURSION_LEVEL;
790    }
791    #endif
792    
793  #ifdef JS_DHASHMETER  #ifdef JS_DHASHMETER
794  #include <math.h>  #include <math.h>
795    

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

  ViewVC Help
Powered by ViewVC 1.1.24