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 2010/10/30 18:17:17 UTC
svn commit: r1029108 - in /subversion/trunk: ./
subversion/libsvn_subr/svn_string.c
subversion/tests/libsvn_subr/string-test.c
Author: stefan2
Date: Sat Oct 30 16:17:16 2010
New Revision: 1029108
URL: http://svn.apache.org/viewvc?rev=1029108&view=rev
Log:
Merge r1028094, r1028104, r1029038 and r1029090 from performance branch.
This change minimizes the memory wasted when allocating
strings of odd size. All memory allocated will actually
be available as string buffer capacity.
Approved by: danielsh
Modified:
subversion/trunk/ (props changed)
subversion/trunk/subversion/libsvn_subr/svn_string.c
subversion/trunk/subversion/tests/libsvn_subr/string-test.c
Propchange: subversion/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat Oct 30 16:17:16 2010
@@ -23,7 +23,7 @@
/subversion/branches/log-g-performance:870941-871032
/subversion/branches/merge-skips-obstructions:874525-874615
/subversion/branches/nfc-nfd-aware-client:870276,870376
-/subversion/branches/performance:982355,983764,983766,984927,984984,985014,985037,985046,985472,985477,985482,985500,985606,985669,987888,987893,995507,995603,1001413,1025660,1028092
+/subversion/branches/performance:982355,983764,983766,984927,984984,985014,985037,985046,985472,985477,985482,985500,985606,985669,987888,987893,995507,995603,1001413,1025660,1028092,1028094,1028104,1029038,1029090
/subversion/branches/ra_serf-digest-authn:875693-876404
/subversion/branches/reintegrate-improvements:873853-874164
/subversion/branches/subtree-mergeinfo:876734-878766
Modified: subversion/trunk/subversion/libsvn_subr/svn_string.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/svn_string.c?rev=1029108&r1=1029107&r2=1029108&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/svn_string.c (original)
+++ subversion/trunk/subversion/libsvn_subr/svn_string.c Sat Oct 30 16:17:16 2010
@@ -250,7 +250,15 @@ create_stringbuf(char *data, apr_size_t
svn_stringbuf_t *
svn_stringbuf_create_ensure(apr_size_t blocksize, apr_pool_t *pool)
{
- char *data = apr_palloc(pool, ++blocksize); /* + space for '\0' */
+ char *data;
+
+ /* 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. */
+
+ ++blocksize; /* + space for '\0' */
+ data = apr_palloc(pool, APR_ALIGN_DEFAULT(blocksize));
data[0] = '\0';
@@ -261,9 +269,7 @@ svn_stringbuf_create_ensure(apr_size_t b
svn_stringbuf_t *
svn_stringbuf_ncreate(const char *bytes, apr_size_t size, apr_pool_t *pool)
{
- /* Ensure string buffer of size + 1 */
svn_stringbuf_t *strbuf = svn_stringbuf_create_ensure(size, pool);
-
memcpy(strbuf->data, bytes, size);
/* Null termination is the convention -- even if we suspect the data
@@ -368,12 +374,18 @@ svn_stringbuf_ensure(svn_stringbuf_t *st
if (str->blocksize < minimum_size)
{
if (str->blocksize == 0)
- str->blocksize = minimum_size;
+ /* APR will increase odd allocation sizes to the next
+ * multiple for 8, for instance. Take advantage of that
+ * knowledge and allow for the extra size to be used. */
+ str->blocksize = APR_ALIGN_DEFAULT(minimum_size);
else
while (str->blocksize < minimum_size)
{
+ /* str->blocksize is aligned;
+ * doubling it should keep it aligned */
apr_size_t prev_size = str->blocksize;
str->blocksize *= 2;
+
/* check for apr_size_t overflow */
if (prev_size > str->blocksize)
{
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=1029108&r1=1029107&r2=1029108&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/string-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/string-test.c Sat Oct 30 16:17:16 2010
@@ -231,12 +231,13 @@ test10(apr_pool_t *pool)
block_len_2 = (s->blocksize);
/* Test that:
- * - The initial block was just the right fit.
+ * - The initial block was at least the right fit.
+ * - The initial block was not excessively large.
* - The block more than doubled (because second string so long).
*/
- if ((len_1 == (block_len_1 - 1))
- && ((block_len_2 / block_len_1) > 2)
- )
+ if ((len_1 <= (block_len_1 - 1))
+ && ((block_len_1 - len_1) <= APR_ALIGN_DEFAULT(1))
+ && ((block_len_2 / block_len_1) > 2))
return SVN_NO_ERROR;
else
return fail(pool, "test failed");