You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2015/04/26 20:58:11 UTC
svn commit: r1676139 - in
/subversion/branches/1.10-cache-improvements/subversion/libsvn_subr:
cache-membuffer.c fnv1a.c fnv1a.h
Author: stefan2
Date: Sun Apr 26 18:58:10 2015
New Revision: 1676139
URL: http://svn.apache.org/r1676139
Log:
On the 1.10-cache-improvements branch:
Use an FNV-1a based hash instead of an MD5 based one for folding long
membuffer cache keys.
* subversion/libsvn_subr/fnv1a.h
(svn__fnv1a_32x4_raw): Declare a FVN-1a variant that produces 128 bits
of hash data.
* subversion/libsvn_subr/fnv1a.c
(svn__fnv1a_32x4_raw): Implement.
* subversion/libsvn_subr/cache-membuffer.c
(combine_long_key): Use the new hash function. Drop the repeated lookup
optimization as it provides no benefit anymore.
Modified:
subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c
subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.c
subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.h
Modified: subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c?rev=1676139&r1=1676138&r2=1676139&view=diff
==============================================================================
--- subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c (original)
+++ subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c Sun Apr 26 18:58:10 2015
@@ -34,10 +34,10 @@
#include "private/svn_atomic.h"
#include "private/svn_dep_compat.h"
#include "private/svn_mutex.h"
-#include "private/svn_pseudo_md5.h"
#include "private/svn_string_private.h"
#include "cache.h"
+#include "fnv1a.h"
/*
* This svn_cache__t implementation actually consists of two parts:
@@ -2605,13 +2605,6 @@ combine_long_key(svn_membuffer_cache_t *
const void *key,
apr_ssize_t key_len)
{
- enum
- {
- /* Max number of NUL bytes to append to KEY to pad it before feeding
- * it our pseudo-MD5 functions. */
- MAX_PADDING = 32
- };
-
apr_uint32_t *digest_buffer;
char *key_copy;
apr_size_t prefix_len = cache->prefix.full_key.size;
@@ -2621,49 +2614,21 @@ combine_long_key(svn_membuffer_cache_t *
if (key_len == APR_HASH_KEY_STRING)
key_len = strlen((const char *) key);
- /* same key as the last time? -> short-circuit */
- if ( key_len + prefix_len == cache->combined_key.entry_key.key_len
- && memcmp((char *)cache->combined_key.full_key.data + prefix_len,
- key, key_len) == 0)
- return;
-
/* Combine keys. */
aligned_key_len = ALIGN_VALUE(key_len);
svn_membuf__ensure(&cache->combined_key.full_key,
- key_len + prefix_len + MAX_PADDING);
+ key_len + prefix_len);
+
key_copy = (char *)cache->combined_key.full_key.data + prefix_len;
cache->combined_key.entry_key.key_len = aligned_key_len + prefix_len;
+ memcpy(key_copy, key, key_len);
+ memset(key_copy + key_len, 0, aligned_key_len - key_len);
+ /* Hash key into 16 bytes. */
digest_buffer = (apr_uint32_t *)cache->combined_key.entry_key.fingerprint;
- if (key_len >= 64)
- {
- /* relatively long key. Use the generic, slow hash code for it */
- memcpy(key_copy, key, key_len);
- memset(key_copy + key_len, 0, aligned_key_len - key_len);
- apr_md5((unsigned char*)digest_buffer, key, key_len);
- }
- else if (key_len < 16)
- {
- memset(key_copy, 0, 16);
- memcpy(key_copy, key, key_len);
-
- svn__pseudo_md5_15(digest_buffer, (const apr_uint32_t *)key_copy);
- }
- else if (key_len < 32)
- {
- memset(key_copy, 0, 32);
- memcpy(key_copy, key, key_len);
-
- svn__pseudo_md5_31(digest_buffer, (const apr_uint32_t *)key_copy);
- }
- else
- {
- memset(key_copy, 0, 64);
- memcpy(key_copy, key, key_len);
-
- svn__pseudo_md5_63(digest_buffer, (const apr_uint32_t *)key_copy);
- }
+ svn__fnv1a_32x4_raw(digest_buffer, key, key_len);
+ /* Combine with prefix. */
cache->combined_key.entry_key.fingerprint[0]
^= cache->prefix.entry_key.fingerprint[0];
cache->combined_key.entry_key.fingerprint[1]
Modified: subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.c
URL: http://svn.apache.org/viewvc/subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.c?rev=1676139&r1=1676138&r2=1676139&view=diff
==============================================================================
--- subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.c (original)
+++ subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.c Sun Apr 26 18:58:10 2015
@@ -132,6 +132,25 @@ svn__fnv1a_32x4(const void *input, apr_s
len - processed);
}
+void
+svn__fnv1a_32x4_raw(apr_uint32_t hashes[4],
+ const void *input,
+ apr_size_t len)
+{
+ apr_size_t processed;
+
+ apr_size_t i;
+ for (i = 0; i < SCALING; ++i)
+ hashes[i] = FNV1_BASE_32;
+
+ /* Process full 16 byte chunks. */
+ processed = fnv1a_32x4(hashes, input, len);
+
+ /* Fold the remainder (if any) into the first hash. */
+ hashes[0] = fnv1a_32(hashes[0], (const char *)input + processed,
+ len - processed);
+}
+
struct svn_fnv1a_32__context_t
{
apr_uint32_t hash;
Modified: subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.h
URL: http://svn.apache.org/viewvc/subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.h?rev=1676139&r1=1676138&r2=1676139&view=diff
==============================================================================
--- subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.h (original)
+++ subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/fnv1a.h Sun Apr 26 18:58:10 2015
@@ -76,6 +76,14 @@ svn_fnv1a_32x4__update(svn_fnv1a_32x4__c
apr_uint32_t
svn_fnv1a_32x4__finalize(svn_fnv1a_32x4__context_t *context);
+/* Set HASHES to the 4 partial hash sums produced by the modified FVN-1a
+ * over INPUT of LEN bytes.
+ */
+void
+svn__fnv1a_32x4_raw(apr_uint32_t hashes[4],
+ const void *input,
+ apr_size_t len);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */