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/10/22 23:02:53 UTC

svn commit: r1710103 - /subversion/trunk/subversion/libsvn_subr/path.c

Author: stefan2
Date: Thu Oct 22 21:02:53 2015
New Revision: 1710103

URL: http://svn.apache.org/viewvc?rev=1710103&view=rev
Log:
Speed up uri_escape() even further by making the EOS test implicit.

Because all strings are NUL-terminated C strings, we can simply mark NUL
as "invalid" in any table we pass to uri_escape; it will never be used
within a string.  Then, we only need to scan up to the first "invalid"
char and then check it for NUL.

This can significantly improve the throughput on newer processors
(Haswell and up) but others will see some benefit, too.

* subversion/libsvn_subr/path.c
  (uri_escape): Verify that the table meets our assumption about NULs
                and then scan the PATH without calculating its length
                first.
  (iri_escape_chars,
   uri_autoescape_chars): Mark NUL as "invalid".

Modified:
    subversion/trunk/subversion/libsvn_subr/path.c

Modified: subversion/trunk/subversion/libsvn_subr/path.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/path.c?rev=1710103&r1=1710102&r2=1710103&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/path.c (original)
+++ subversion/trunk/subversion/libsvn_subr/path.c Thu Oct 22 21:02:53 2015
@@ -910,18 +910,22 @@ uri_escape(const char *path, const char
   svn_stringbuf_t *retstr;
   apr_size_t i, copied = 0;
   int c;
-  apr_size_t len = strlen(path);
+  apr_size_t len;
   const char *p, *end;
 
+  /* To terminate our scanning loop, table[NUL] must report "invalid". */
+  assert(table[0] == 0);
+
   /* Quick check: Does any character need escaping? */
-  for (p = path, end = p + len; p < end; ++p)
-    if (!table[(unsigned char)*p])
-      break;
+  for (p = path; table[(unsigned char)*p]; ++p)
+    {}
 
-  if (p == end)
+  /* No char to escape before EOS? */
+  if (*p == '\0')
     return path;
 
   /* We need to escape at least one character. */
+  len = strlen(p) + (p - path);
   retstr = svn_stringbuf_create_ensure(len, pool);
   for (i = p - path; i < len; i++)
     {
@@ -978,7 +982,7 @@ svn_path_uri_encode(const char *path, ap
 }
 
 static const char iri_escape_chars[256] = {
-  1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
+  0, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
@@ -1005,7 +1009,7 @@ svn_path_uri_from_iri(const char *iri, a
 }
 
 static const char uri_autoescape_chars[256] = {
-  1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
+  0, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
   0, 1, 0, 1, 1, 1, 1, 1,  1, 1, 1, 1, 1, 1, 1, 1,
   1, 1, 1, 1, 1, 1, 1, 1,  1, 1, 1, 1, 0, 1, 0, 1,