You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by br...@apache.org on 2014/02/21 22:13:28 UTC

svn commit: r1570706 - in /subversion/trunk/subversion/libsvn_fs_base: key-gen.c key-gen.h

Author: breser
Date: Fri Feb 21 21:13:28 2014
New Revision: 1570706

URL: http://svn.apache.org/r1570706
Log:
Remove the overthought svn_fs_base__key_compare() function.

The old implmenetation ran strlen() on both strings, which in my opinion is a
really dubious optimization.  I kinda doubt that walking both strings twice in
cases where the key is the same size is optimally better than saving the
character comparisons when they are different sizes.  I'd bet that we're
comparing identically sized strings a lot of the time.  Forcing -1, 0, or 1
as the only return values seems entirely pointless to me since the only thing
we ever do is test for 0 when calling this.

This incidentally fixes a compiler warning since we we were putting the return
of strlen into an int which isn't necessarily the same size as the strlen().

* subversion/libsvn_fs_base/key-gen.h
  (svn_fs_base__key_compare): Convert the function to a macro to strcmp and
    update the documentation to not promise things strcmp() doesn't promise.

* subversion/libsvn_fs_base/key-gen.c
  (svn_fs_base__key_compare): Delete.


Modified:
    subversion/trunk/subversion/libsvn_fs_base/key-gen.c
    subversion/trunk/subversion/libsvn_fs_base/key-gen.h

Modified: subversion/trunk/subversion/libsvn_fs_base/key-gen.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_base/key-gen.c?rev=1570706&r1=1570705&r2=1570706&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_base/key-gen.c (original)
+++ subversion/trunk/subversion/libsvn_fs_base/key-gen.c Fri Feb 21 21:13:28 2014
@@ -109,22 +109,6 @@ svn_fs_base__next_key(const char *this, 
 }
 
 
-int
-svn_fs_base__key_compare(const char *a, const char *b)
-{
-  int a_len = strlen(a);
-  int b_len = strlen(b);
-  int cmp;
-
-  if (a_len > b_len)
-    return 1;
-  if (b_len > a_len)
-    return -1;
-  cmp = strcmp(a, b);
-  return (cmp ? (cmp / abs(cmp)) : 0);
-}
-
-
 svn_boolean_t
 svn_fs_base__same_keys(const char *a, const char *b)
 {

Modified: subversion/trunk/subversion/libsvn_fs_base/key-gen.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_base/key-gen.h?rev=1570706&r1=1570705&r2=1570706&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_base/key-gen.h (original)
+++ subversion/trunk/subversion/libsvn_fs_base/key-gen.h Fri Feb 21 21:13:28 2014
@@ -80,10 +80,10 @@ void svn_fs_base__next_key(const char *t
 
 /* Compare two strings A and B as base-36 alphanumeric keys.
  *
- * Return -1, 0, or 1 if A is less than, equal to, or greater than B,
- * respectively.
+ * Return an integer value less than zero, zero, or greater than zero if A is
+ * less than, equal to, or greater than B, respectively.
  */
-int svn_fs_base__key_compare(const char *a, const char *b);
+#define svn_fs_base__key_compare strcmp
 
 /* Compare two strings A and B as base-36 alphanumber keys.
  *