[svn:parrot] r48006 - branches/hash_allocator/src

whiteknight at svn.parrot.org whiteknight at svn.parrot.org
Mon Jul 5 10:36:46 UTC 2010


Author: whiteknight
Date: Mon Jul  5 10:36:45 2010
New Revision: 48006
URL: https://trac.parrot.org/parrot/changeset/48006

Log:
[hash] use alloc instead of realloc. This gets rid of those assertion failures (which I've now deleted), but causes a failed assertion in miniparrot's GC.

Modified:
   branches/hash_allocator/src/hash.c

Modified: branches/hash_allocator/src/hash.c
==============================================================================
--- branches/hash_allocator/src/hash.c	Mon Jul  5 07:35:02 2010	(r48005)
+++ branches/hash_allocator/src/hash.c	Mon Jul  5 10:36:45 2010	(r48006)
@@ -818,39 +818,34 @@
     const UINTVAL new_size = old_size * 2;
     const UINTVAL new_mask = new_size - 1;
     UINTVAL i;
+    const UINTVAL total_size = HASH_ALLOC_SIZE(new_size);
     HashBucket ** const old_bi = hash->bucket_indices;
     HashBucket ** const new_bi =
-        (HashBucket ** const)Parrot_gc_reallocate_memory_chunk(interp,
-            hash->bucket_indices, new_size * sizeof (HashBucket *));
-
-    for (i = 0; i < old_size; i++) {
-        PARROT_ASSERT(old_bi[i] == new_bi[i]);
-    }
+        (HashBucket ** const)Parrot_gc_allocate_memory_chunk(interp,
+            total_size);
 
-    memset(new_bi + old_size, 0, sizeof (HashBucket *) * old_size);
+    memset(new_bi, 0, total_size);
 
     /* update hash data */
-    hash->mask           = new_mask;
-    hash->bucket_indices = new_bi;
+
 
     /* Recalculate the index for each bucket. Some will stay where they are,
        some will move to a new index. */
     for (i = 0; i < old_size; ++i) {
-        HashBucket *b = hash->bucket_indices[i];
+        HashBucket *b = old_bi[i];
 
         while (b) {
             const size_t new_loc =
                 (hash->hash_val)(interp, b->key, hash->seed) & (new_mask);
             HashBucket * const next_b = b->next;
-            if (i != new_loc) {
-                PARROT_ASSERT(b != new_bi[new_loc]);
-                b->next         = new_bi[new_loc];
-                new_bi[new_loc] = b;
-            }
-            PARROT_ASSERT(b != next_b);
+            b->next         = new_bi[new_loc];
+            new_bi[new_loc] = b;
             b = next_b;
         }
     }
+    hash->mask           = new_mask;
+    hash->bucket_indices = new_bi;
+    Parrot_gc_free_memory_chunk(interp, old_bi);
 }
 
 
@@ -978,12 +973,13 @@
     const INTVAL numbuckets = N_BUCKETS(INITIAL_BUCKETS);
     Hash * const hash       =
         (Hash *)Parrot_gc_allocate_fixed_size_storage(interp, sizeof (Hash));
+    const INTVAL total_size = HASH_ALLOC_SIZE(INITIAL_BUCKETS);
     HashBucket ** const bp =
         (HashBucket ** const)Parrot_gc_allocate_memory_chunk(interp,
-            HASH_ALLOC_SIZE(INITIAL_BUCKETS));
+            total_size);
 
     PARROT_ASSERT(INITIAL_BUCKETS % 4 == 0);
-
+    memset(bp, 0, total_size);
     hash->compare        = compare;
     hash->hash_val       = keyhash;
     hash->entry_type     = val_type;


More information about the parrot-commits mailing list