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 2012/11/09 02:01:24 UTC

svn commit: r1407337 - in /subversion/branches/wc-collate-path/subversion: include/private/svn_string_private.h libsvn_subr/string.c

Author: brane
Date: Fri Nov  9 01:01:24 2012
New Revision: 1407337

URL: http://svn.apache.org/viewvc?rev=1407337&view=rev
Log:
On the wc-collate-paths branch: Prepare to horrendously abuse stringbufs
as general-purpose, growable memory buffers.

* subversion/include/private/svn_string_private.h (svn_stringbuf__reserve): New.
* subversion/libsvn_subr/string.c (my__realloc): Remove.
  (svn_stringbuf__reserve): Implments stringbuf memory reallocation but does
   not touch the data or the length.
  (svn_stringbuf_ensure): Reimplement using svn_stringbuf__reserve.

Modified:
    subversion/branches/wc-collate-path/subversion/include/private/svn_string_private.h
    subversion/branches/wc-collate-path/subversion/libsvn_subr/string.c

Modified: subversion/branches/wc-collate-path/subversion/include/private/svn_string_private.h
URL: http://svn.apache.org/viewvc/subversion/branches/wc-collate-path/subversion/include/private/svn_string_private.h?rev=1407337&r1=1407336&r2=1407337&view=diff
==============================================================================
--- subversion/branches/wc-collate-path/subversion/include/private/svn_string_private.h (original)
+++ subversion/branches/wc-collate-path/subversion/include/private/svn_string_private.h Fri Nov  9 01:01:24 2012
@@ -54,6 +54,13 @@ extern "C" {
 svn_string_t *
 svn_stringbuf__morph_into_string(svn_stringbuf_t *strbuf);
 
+/** Like svn_stringbuf_ensure, but does not reserve space for the '\0'
+ * and does not copy the data.
+ */
+void
+svn_stringbuf__reserve(svn_stringbuf_t *str, apr_size_t minimum_size);
+
+
 /** Like apr_strtoff but provided here for backward compatibility
  *  with APR 0.9 */
 apr_status_t

Modified: subversion/branches/wc-collate-path/subversion/libsvn_subr/string.c
URL: http://svn.apache.org/viewvc/subversion/branches/wc-collate-path/subversion/libsvn_subr/string.c?rev=1407337&r1=1407336&r2=1407337&view=diff
==============================================================================
--- subversion/branches/wc-collate-path/subversion/libsvn_subr/string.c (original)
+++ subversion/branches/wc-collate-path/subversion/libsvn_subr/string.c Fri Nov  9 01:01:24 2012
@@ -37,32 +37,6 @@
 #include "svn_private_config.h"
 
 
-/* Our own realloc, since APR doesn't have one.  Note: this is a
-   generic realloc for memory pools, *not* for strings. */
-static void *
-my__realloc(char *data, apr_size_t oldsize, apr_size_t request,
-            apr_pool_t *pool)
-{
-  void *new_area;
-
-  /* kff todo: it's a pity APR doesn't give us this -- sometimes it
-     could realloc the block merely by extending in place, sparing us
-     a memcpy(), but only the pool would know enough to be able to do
-     this.  We should add a realloc() to APR if someone hasn't
-     already. */
-
-  /* malloc new area */
-  new_area = apr_palloc(pool, request);
-
-  /* copy data to new area */
-  memcpy(new_area, data, oldsize);
-
-  /* I'm NOT freeing old area here -- cuz we're using pools, ugh. */
-
-  /* return new area */
-  return new_area;
-}
-
 static APR_INLINE svn_boolean_t
 string_compare(const char *str1,
                const char *str2,
@@ -442,10 +416,8 @@ svn_stringbuf_isempty(const svn_stringbu
 
 
 void
-svn_stringbuf_ensure(svn_stringbuf_t *str, apr_size_t minimum_size)
+svn_stringbuf__reserve(svn_stringbuf_t *str, apr_size_t minimum_size)
 {
-  ++minimum_size;  /* + space for '\0' */
-
   /* Keep doubling capacity until have enough. */
   if (str->blocksize < minimum_size)
     {
@@ -470,15 +442,25 @@ svn_stringbuf_ensure(svn_stringbuf_t *st
               }
           }
 
-      str->data = (char *) my__realloc(str->data,
-                                       str->len + 1,
-                                       /* We need to maintain (and thus copy)
-                                          the trailing nul */
-                                       str->blocksize,
-                                       str->pool);
+      str->data = apr_palloc(str->pool, str->blocksize);
+      /* Note that we do not touch str->len. It's up to the caller to
+         reset it, or copy the old data, or do whatever magic it
+         wants. */
     }
 }
 
+void
+svn_stringbuf_ensure(svn_stringbuf_t *str, apr_size_t minimum_size)
+{
+  const char *old_data = str->data;
+
+  /* Reserve space for the required size and don't forget the '\0' */
+  svn_stringbuf__reserve(str, minimum_size + 1);
+
+  /* Copy the data. We need to maintain (and thus copy) the trailing nul */
+  memcpy(str->data, old_data, str->len + 1);
+}
+
 
 /* WARNING - Optimized code ahead!
  * This function has been hand-tuned for performance. Please read