subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1412554 - in /subversion/trunk/subversion: include/private/svn_string_private.h libsvn_subr/string.c tests/libsvn_subr/string-test.c
Date Thu, 22 Nov 2012 14:00:49 GMT
Author: brane
Date: Thu Nov 22 14:00:48 2012
New Revision: 1412554

URL: http://svn.apache.org/viewvc?rev=1412554&view=rev
Log:
Groundwork for issue #4261. Add svn_string_t based similarity scorer.

* subversion/include/private/svn_string_private.h
  (svn_string__similarity): New prototype.
* subversion/libsvn_subr/string.c
  (svn_string__similarity): Rename from svn_cstring__similarity.
   Fix suffix scanner to not rely on NUL-termination.
  (svn_cstring__similarity): Reimplement as wrapper of svn_string__similarity.
* subversion/tests/libsvn_subr/string-test.c
  (test_string_similarity): Add test for sized, non-NUL-terminated case.

Modified:
    subversion/trunk/subversion/include/private/svn_string_private.h
    subversion/trunk/subversion/libsvn_subr/string.c
    subversion/trunk/subversion/tests/libsvn_subr/string-test.c

Modified: subversion/trunk/subversion/include/private/svn_string_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_string_private.h?rev=1412554&r1=1412553&r2=1412554&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_string_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_string_private.h Thu Nov 22 14:00:48 2012
@@ -200,6 +200,16 @@ unsigned int
 svn_cstring__similarity(const char *stra, const char *strb,
                         svn_membuf_t *buffer, apr_size_t *rlcs);
 
+/**
+ * Like svn_cstring__similarity, but accepts svn_string_t's instead
+ * of NUL-terminated character strings.
+ */
+unsigned int
+svn_string__similarity(const svn_string_t *stringa,
+                       const svn_string_t *stringb,
+                       svn_membuf_t *buffer, apr_size_t *rlcs);
+
+
 /** @} */
 
 /** @} */

Modified: subversion/trunk/subversion/libsvn_subr/string.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/string.c?rev=1412554&r1=1412553&r2=1412554&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/string.c (original)
+++ subversion/trunk/subversion/libsvn_subr/string.c Thu Nov 22 14:00:48 2012
@@ -1185,8 +1185,20 @@ unsigned int
 svn_cstring__similarity(const char *stra, const char *strb,
                         svn_membuf_t *buffer, apr_size_t *rlcs)
 {
-  const apr_size_t lena = strlen(stra);
-  const apr_size_t lenb = strlen(strb);
+  const svn_string_t stringa = {stra, strlen(stra)};
+  const svn_string_t stringb = {strb, strlen(strb)};
+  return svn_string__similarity(&stringa, &stringb, buffer, rlcs);
+}
+
+unsigned int
+svn_string__similarity(const svn_string_t *stringa,
+                       const svn_string_t *stringb,
+                       svn_membuf_t *buffer, apr_size_t *rlcs)
+{
+  const char *stra = stringa->data;
+  const char *strb = stringb->data;
+  const apr_size_t lena = stringa->len;
+  const apr_size_t lenb = stringb->len;
   const apr_size_t total = lena + lenb;
   const char *enda = stra + lena;
   const char *endb = strb + lenb;
@@ -1200,11 +1212,13 @@ svn_cstring__similarity(const char *stra
     }
 
   /* ... and the common suffix */
-  while (stra < enda && strb < endb && *enda == *endb)
-    {
-      --enda; --endb;
-      ++lcs;
-    }
+  if (stra < enda && strb < endb)
+    do
+      {
+        --enda; --endb;
+        ++lcs;
+      }
+    while (stra < enda && strb < endb && *enda == *endb);
 
   if (stra < enda && strb < endb)
     {
@@ -1254,7 +1268,7 @@ svn_cstring__similarity(const char *stra
           }
         }
 
-      /* The common suffix matcher always finds the nul terminator,
+      /* The common suffix matcher always incremnts the lcs
          so subtract 1 from the result. */
       lcs += prev[slots] - 1;
     }

Modified: subversion/trunk/subversion/tests/libsvn_subr/string-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/string-test.c?rev=1412554&r1=1412553&r2=1412554&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/string-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/string-test.c Thu Nov 22 14:00:48 2012
@@ -699,6 +699,15 @@ test_string_similarity(apr_pool_t *pool)
                     t->stra, t->strb, lcs, t->lcs);
     }
 
+  /* Test partial similarity */
+  {
+    const svn_string_t foo = {"svn:foo", 4};
+    const svn_string_t bar = {"svn:bar", 4};
+    if (1000 != svn_string__similarity(&foo, &bar, &buffer, NULL))
+      return fail(pool, "'%s'[:4] ~ '%s'[:4] found different",
+                  foo.data, bar.data);
+  }
+
   return SVN_NO_ERROR;
 }
 



Mime
View raw message