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/05/03 18:00:44 UTC

svn commit: r1677430 - /subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c

Author: stefan2
Date: Sun May  3 16:00:44 2015
New Revision: 1677430

URL: http://svn.apache.org/r1677430
Log:
On the 1.10-cache-improvements:
Introduce a entry_key_t comparison function.

Using memcmp for struct comparison relies on padding bytes being
initialized properly.  In membuffer, this is accidentally the case
but we should not rely on it.

* subversion/libsvn_subr/cache-membuffer.c
  (entry_keys_match): New utility function.
  (find_entry): Use the above for entry key comparison.

Modified:
    subversion/branches/1.10-cache-improvements/subversion/libsvn_subr/cache-membuffer.c

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=1677430&r1=1677429&r2=1677430&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 May  3 16:00:44 2015
@@ -1174,6 +1174,17 @@ let_entry_age(svn_membuffer_t *cache, en
     }
 }
 
+/* Return whether the keys in LHS and RHS match.
+ */
+static svn_boolean_t
+entry_keys_match(const entry_key_t *lhs,
+                 const entry_key_t *rhs)
+{
+  return (lhs->fingerprint[0] == rhs->fingerprint[0])
+      && (lhs->fingerprint[1] == rhs->fingerprint[1])
+      && (lhs->key_len == rhs->key_len);
+}
+
 /* Given the GROUP_INDEX that shall contain an entry with the hash key
  * TO_FIND, find that entry in the specified group.
  *
@@ -1221,8 +1232,7 @@ find_entry(svn_membuffer_t *cache,
   while (1)
     {
       for (i = 0; i < group->header.used; ++i)
-        if (memcmp(&group->entries[i].key, &to_find->entry_key,
-                   sizeof(to_find->entry_key)) == 0)
+        if (entry_keys_match(&group->entries[i].key, &to_find->entry_key))
           {
             /* This is the only entry that _may_ contain the correct data. */
             entry = &group->entries[i];