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 2013/10/15 06:59:00 UTC

svn commit: r1532186 - /subversion/trunk/subversion/libsvn_subr/string.c

Author: stefan2
Date: Tue Oct 15 04:59:00 2013
New Revision: 1532186

URL: http://svn.apache.org/r1532186
Log:
Minor optimization in svn_membuf code.

* subversion/libsvn_subr/string.c
  (membuf_create): always allocate, even 0 bytes
  (svn_membuf__resize): new allocated membuf->data can never be NULL

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

Modified: subversion/trunk/subversion/libsvn_subr/string.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/string.c?rev=1532186&r1=1532185&r2=1532186&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/string.c (original)
+++ subversion/trunk/subversion/libsvn_subr/string.c Tue Oct 15 04:59:00 2013
@@ -53,9 +53,9 @@ membuf_create(void **data, apr_size_t *s
   /* apr_palloc will allocate multiples of 8.
    * Thus, we would waste some of that memory if we stuck to the
    * smaller size. Note that this is safe even if apr_palloc would
-   * use some other aligment or none at all. */
+   * use some other alignment or none at all. */
   minimum_size = APR_ALIGN_DEFAULT(minimum_size);
-  *data = (!minimum_size ? NULL : apr_palloc(pool, minimum_size));
+  *data = apr_palloc(pool, minimum_size);
   *size = minimum_size;
 }
 
@@ -121,7 +121,10 @@ svn_membuf__resize(svn_membuf_t *membuf,
   const apr_size_t old_size = membuf->size;
 
   membuf_ensure(&membuf->data, &membuf->size, size, membuf->pool);
-  if (membuf->data && old_data && old_data != membuf->data)
+
+  /* If we re-allocated MEMBUF->DATA, it cannot be NULL.
+   * Statically initialized membuffers (OLD_DATA) may be NULL, though. */
+  if (old_data && old_data != membuf->data)
     memcpy(membuf->data, old_data, old_size);
 }