subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject svn commit: r1759177 - in /subversion/trunk/subversion: libsvn_subr/string.c tests/libsvn_subr/string-test.c
Date Sun, 04 Sep 2016 12:31:30 GMT
Author: ivan
Date: Sun Sep  4 12:31:30 2016
New Revision: 1759177

URL: http://svn.apache.org/viewvc?rev=1759177&view=rev
Log:
Save few cycles in svn_stringbuf_set().

* subversion/libsvn_subr/string.c
  (svn_stringbuf_set): Do not use svn_stringbuf_ensure() because it will
   preserve existing stringbuf content if any. Use membuf_ensure() directly.

* subversion/tests/libsvn_subr/string-test.c
  (test_stringbuf_set): Add simple tests for svn_stringbuf_set().
  (test_funcs): Add test.

Modified:
    subversion/trunk/subversion/libsvn_subr/string.c
    subversion/trunk/subversion/tests/libsvn_subr/string-test.c

Modified: subversion/trunk/subversion/libsvn_subr/string.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/string.c?rev=1759177&r1=1759176&r2=1759177&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/string.c (original)
+++ subversion/trunk/subversion/libsvn_subr/string.c Sun Sep  4 12:31:30 2016
@@ -479,7 +479,7 @@ svn_stringbuf_set(svn_stringbuf_t *str,
 {
   apr_size_t amt = strlen(value);
 
-  svn_stringbuf_ensure(str, amt);
+  membuf_ensure(&str->data, &str->blocksize, amt + 1, str->pool);
   memcpy(str->data, value, amt + 1);
   str->len = amt;
 }

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=1759177&r1=1759176&r2=1759177&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/string-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/string-test.c Sun Sep  4 12:31:30 2016
@@ -893,6 +893,33 @@ test_cstring_skip_prefix(apr_pool_t *poo
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_stringbuf_set(apr_pool_t *pool)
+{
+  svn_stringbuf_t *str = svn_stringbuf_create_empty(pool);
+
+  SVN_TEST_STRING_ASSERT(str->data, "");
+  SVN_TEST_INT_ASSERT(str->len, 0);
+
+  svn_stringbuf_set(str, "0123456789");
+  SVN_TEST_STRING_ASSERT(str->data, "0123456789");
+  SVN_TEST_INT_ASSERT(str->len, 10);
+
+  svn_stringbuf_set(str, "");
+  SVN_TEST_STRING_ASSERT(str->data, "");
+  SVN_TEST_INT_ASSERT(str->len, 0);
+
+  svn_stringbuf_set(str, "0123456789abcdef");
+  SVN_TEST_STRING_ASSERT(str->data, "0123456789abcdef");
+  SVN_TEST_INT_ASSERT(str->len, 16);
+
+  svn_stringbuf_set(str, "t");
+  SVN_TEST_STRING_ASSERT(str->data, "t");
+  SVN_TEST_INT_ASSERT(str->len, 1);
+
+  return SVN_NO_ERROR;
+}
+
 /*
    ====================================================================
    If you add a new test to this file, update this array.
@@ -969,6 +996,8 @@ static struct svn_test_descriptor_t test
                    "test string matching"),
     SVN_TEST_PASS2(test_cstring_skip_prefix,
                    "test svn_cstring_skip_prefix()"),
+    SVN_TEST_PASS2(test_stringbuf_set,
+                   "test svn_stringbuf_set()"),
     SVN_TEST_NULL
   };
 



Mime
View raw message