subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stef...@apache.org
Subject svn commit: r1495805 - /subversion/trunk/subversion/libsvn_fs_fs/tree.c
Date Sun, 23 Jun 2013 10:36:19 GMT
Author: stefan2
Date: Sun Jun 23 10:36:19 2013
New Revision: 1495805

URL: http://svn.apache.org/r1495805
Log:
Simplify the hash function used for the DAG node cache.

* subversion/libsvn_fs_fs/tree.c
  (cache_entry_t): peg hash_value to unsigned 32 bits which minimizes
                   the number of casts we have to do
  (cache_lookup): same here, including FACTOR;
                  drop the chunky alternative to unaligned data access

Modified:
    subversion/trunk/subversion/libsvn_fs_fs/tree.c

Modified: subversion/trunk/subversion/libsvn_fs_fs/tree.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_fs/tree.c?rev=1495805&r1=1495804&r2=1495805&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_fs/tree.c (original)
+++ subversion/trunk/subversion/libsvn_fs_fs/tree.c Sun Jun 23 10:36:19 2013
@@ -151,7 +151,7 @@ typedef struct cache_entry_t
 {
   /* hash value derived from PATH, REVISION.
      Used to short-circuit failed lookups. */
-  long int hash_value;
+  apr_uint32_t hash_value;
 
   /* revision to which the NODE belongs */
   svn_revnum_t revision;
@@ -340,10 +340,10 @@ cache_lookup( fs_fs_dag_cache_t *cache
 {
   apr_size_t i, bucket_index;
   apr_size_t path_len = strlen(path);
-  long int hash_value = revision;
+  apr_uint32_t hash_value = (apr_uint32_t)revision;
 
   /* "randomizing" / distributing factor used in our hash function */
-  enum { factor = 0xd1f3da69 };
+  const apr_uint32_t factor = 0xd1f3da69;
 
   /* optimistic lookup: hit the same bucket again? */
   cache_entry_t *result = &cache->buckets[cache->last_hit];
@@ -365,23 +365,8 @@ cache_lookup( fs_fs_dag_cache_t *cache
    */
   for (; i + 8 <= path_len; i += 8)
     hash_value = hash_value * factor * factor
-               + (  (long int)*(const apr_uint32_t*)(path + i) * factor
-                  + (long int)*(const apr_uint32_t*)(path + i + 4));
-#else
-  for (; i + 4 <= path_len; i += 4)
-    {
-      /* read the data in BIG-ENDIAN order
-         (it's just simpler code and most of the machines in question are
-          actually big endian) */
-      apr_uint32_t val = 0;
-      int j;
-
-      /* most compilers will unroll this loop: */
-      for (j = 0; j < 4; j++)
-        val = (val << 8) + (unsigned char)path[i + j];
-
-      hash_value = hash_value * factor + val;
-    }
+               + (  *(const apr_uint32_t*)(path + i) * factor
+                  + *(const apr_uint32_t*)(path + i + 4));
 #endif
 
   for (; i < path_len; ++i)



Mime
View raw message