[svn:parrot] r48392 - trunk/src

chromatic at svn.parrot.org chromatic at svn.parrot.org
Tue Aug 10 23:50:09 UTC 2010


Author: chromatic
Date: Tue Aug 10 23:50:07 2010
New Revision: 48392
URL: https://trac.parrot.org/parrot/changeset/48392

Log:
[hash] Switched hash mark to linear bucket scan.

This patch provides a modest performance improvement and better processor cache behavior.

Patch courtesy Luben Karavelov <luben at unixsol.org>

Modified:
   trunk/src/hash.c

Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c	Tue Aug 10 22:49:37 2010	(r48391)
+++ trunk/src/hash.c	Tue Aug 10 23:50:07 2010	(r48392)
@@ -508,23 +508,20 @@
 parrot_mark_hash_keys(PARROT_INTERP, ARGIN(Hash *hash))
 {
     ASSERT_ARGS(parrot_mark_hash_keys)
-    UINTVAL entries = hash->entries;
-    UINTVAL found   = 0;
-    INTVAL  i;
+    const UINTVAL entries = hash->entries;
+    UINTVAL found = 0;
+    UINTVAL i;
 
-    for (i = hash->mask; i >= 0; --i) {
-        HashBucket *bucket = hash->bucket_indices[i];
+    HashBucket *bucket = hash->buckets;
 
-        while (bucket) {
-            if (++found > entries)
-                Parrot_ex_throw_from_c_args(interp, NULL, 1,
-                    "Detected hash corruption at hash %p entries %d",
-                    hash, (int)entries);
+    for (i= 0; i <= hash->mask; ++i, ++bucket) {
+        if (bucket->key){
 
             PARROT_ASSERT(bucket->key);
             Parrot_gc_mark_PObj_alive(interp, (PObj *)bucket->key);
 
-            bucket = bucket->next;
+            if (++found >= entries)
+                break;
         }
     }
 }
@@ -545,22 +542,19 @@
 {
     ASSERT_ARGS(parrot_mark_hash_values)
     const UINTVAL entries = hash->entries;
-    UINTVAL found   = 0;
-    INTVAL  i;
+    UINTVAL found = 0;
+    UINTVAL i;
 
-    for (i = hash->mask; i >= 0; --i) {
-        HashBucket *bucket = hash->bucket_indices[i];
+    HashBucket *bucket = hash->buckets;
 
-        while (bucket) {
-            if (++found > entries)
-                Parrot_ex_throw_from_c_args(interp, NULL, 1,
-                        "Detected hash corruption at hash %p entries %d",
-                        hash, (int)entries);
+    for (i= 0; i <= hash->mask; ++i, ++bucket) {
+        if (bucket->key){
 
             PARROT_ASSERT(bucket->value);
             Parrot_gc_mark_PObj_alive(interp, (PObj *)bucket->value);
 
-            bucket = bucket->next;
+            if (++found >= entries)
+                break;
         }
     }
 }
@@ -580,30 +574,25 @@
 {
     ASSERT_ARGS(parrot_mark_hash_both)
     const UINTVAL entries = hash->entries;
-    UINTVAL found   = 0;
-    INTVAL  i;
+    UINTVAL found = 0;
+    UINTVAL i;
 
-    for (i = hash->mask; i >= 0; --i) {
-        HashBucket *bucket = hash->bucket_indices[i];
-
-        while (bucket) {
-            if (++found > entries)
-                Parrot_ex_throw_from_c_args(interp, NULL, 1,
-                        "Detected hash corruption at hash %p entries %d",
-                        hash, (int)entries);
+    HashBucket *bucket = hash->buckets;
 
+    for (i= 0; i <= hash->mask; ++i, ++bucket) {
+        if (bucket->key){
             PARROT_ASSERT(bucket->key);
             Parrot_gc_mark_PObj_alive(interp, (PObj *)bucket->key);
 
             PARROT_ASSERT(bucket->value);
             Parrot_gc_mark_PObj_alive(interp, (PObj *)bucket->value);
 
-            bucket = bucket->next;
+            if (++found >= entries)
+                break;
         }
     }
 }
 
-
 /*
 
 =item C<static void hash_thaw(PARROT_INTERP, Hash *hash, PMC *info)>


More information about the parrot-commits mailing list