[svn:parrot] r48274 - trunk/src

chromatic at svn.parrot.org chromatic at svn.parrot.org
Tue Aug 3 05:31:33 UTC 2010


Author: chromatic
Date: Tue Aug  3 05:31:33 2010
New Revision: 48274
URL: https://trac.parrot.org/parrot/changeset/48274

Log:
[hash] Added get_hash_val().
This avoids the overhead of a function call to get a cached STRING hashval and
speeds up the Rakudo startup benchmark by 1%.

Modified:
   trunk/src/hash.c

Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c	Tue Aug  3 04:38:52 2010	(r48273)
+++ trunk/src/hash.c	Tue Aug  3 05:31:33 2010	(r48274)
@@ -50,6 +50,12 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*hash);
 
+static UINTVAL get_hash_val(PARROT_INTERP,
+    ARGIN(Hash *hash),
+    ARGIN_NULLOK(void *key))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
 static void hash_freeze(PARROT_INTERP,
     ARGIN(const Hash *hash),
     ARGMOD(PMC *info))
@@ -103,6 +109,9 @@
 #define ASSERT_ARGS_expand_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(hash))
+#define ASSERT_ARGS_get_hash_val __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(hash))
 #define ASSERT_ARGS_hash_freeze __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(hash) \
@@ -156,6 +165,30 @@
 
 /*
 
+=item C<static UINTVAL get_hash_val(PARROT_INTERP, Hash *hash, void *key)>
+
+An inlinable helper function to avoid the overhead of calling key_hash_STRING()
+when there's already a calculated hash value for the STRING key.
+
+=cut
+
+*/
+
+static UINTVAL
+get_hash_val(PARROT_INTERP, ARGIN(Hash *hash), ARGIN_NULLOK(void *key))
+{
+    if (hash->hash_val == key_hash_STRING) {
+        STRING *s = (STRING *)key;
+        if (s->hashval)
+            return s->hashval;
+    }
+
+    return (hash->hash_val)(interp, key, hash->seed);
+}
+
+
+/*
+
 =item C<int STRING_compare(PARROT_INTERP, const void *search_key, const void
 *bucket_key)>
 
@@ -1339,7 +1372,7 @@
         ARGIN_NULLOK(void *key), ARGIN_NULLOK(void *value))
 {
     ASSERT_ARGS(parrot_hash_put)
-    const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
+    const UINTVAL hashval = get_hash_val(interp, hash, key);
     HashBucket   *bucket  = hash->bucket_indices[hashval & hash->mask];
 
     /* When the hash is constant, check that the key and value are also


More information about the parrot-commits mailing list