summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%netscape.com <devnull@localhost>2001-08-07 05:36:22 +0000
committerwtc%netscape.com <devnull@localhost>2001-08-07 05:36:22 +0000
commit1be0fced729ab31372b0cd38b8f14e6d6f7dcd1e (patch)
treebd38ce7ff28d1d6157fbf080166d594acf2306b2
parent676ad94ebfc91521152edf0fd7fea9d1ab1c3da1 (diff)
downloadnspr-hg-1be0fced729ab31372b0cd38b8f14e6d6f7dcd1e.tar.gz
Bugzilla bug #92810: increment or decrement the hashtable shift counter
only after we have successfully allocated the new buckets. The patch is from Brendan Eich.
-rw-r--r--lib/ds/plhash.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/ds/plhash.c b/lib/ds/plhash.c
index 9705d87d..f02b5132 100644
--- a/lib/ds/plhash.c
+++ b/lib/ds/plhash.c
@@ -250,10 +250,6 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
/* Grow the table if it is overloaded */
n = NBUCKETS(ht);
if (ht->nentries >= OVERLOADED(n)) {
-#ifdef HASHMETER
- ht->ngrows++;
-#endif
- ht->shift--;
oldbuckets = ht->buckets;
#if defined(WIN16)
if (2 * n > 16000)
@@ -267,6 +263,10 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
return 0;
}
memset(ht->buckets, 0, nb);
+#ifdef HASHMETER
+ ht->ngrows++;
+#endif
+ ht->shift--;
for (i = 0; i < n; i++) {
for (he = oldbuckets[i]; he; he = next) {
@@ -332,10 +332,6 @@ PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
/* Shrink table if it's underloaded */
n = NBUCKETS(ht);
if (--ht->nentries < UNDERLOADED(n)) {
-#ifdef HASHMETER
- ht->nshrinks++;
-#endif
- ht->shift++;
oldbuckets = ht->buckets;
nb = n * sizeof(PLHashEntry*) / 2;
ht->buckets = (PLHashEntry**)(
@@ -345,6 +341,10 @@ PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
return;
}
memset(ht->buckets, 0, nb);
+#ifdef HASHMETER
+ ht->nshrinks++;
+#endif
+ ht->shift++;
for (i = 0; i < n; i++) {
for (he = oldbuckets[i]; he; he = next) {