Author: stefan2
Date: Wed Oct 27 20:47:06 2010
New Revision: 1028094
URL: http://svn.apache.org/viewvc?rev=1028094&view=rev
Log:
If we allocate stringbufs, their actual capacity allocated by APR
is often larger than requested. Take advantage of that by requesting
an enlarged buffer in the first place. Especially for short or empty
strings, this saves some re-allocations once they grow.
* subversion/libsvn_subr/svn_string.c
(svn_stringbuf_ncreate): allocate a buffer of aligned size
Modified:
subversion/branches/performance/subversion/libsvn_subr/svn_string.c
Modified: subversion/branches/performance/subversion/libsvn_subr/svn_string.c
URL:
http://svn.apache.org/viewvc/subversion/branches/performance/subversion/libsvn_subr/svn_string.c?rev=1028094&r1=1028093&r2=1028094&view=diff
==============================================================================
--- subversion/branches/performance/subversion/libsvn_subr/svn_string.c
(original)
+++ subversion/branches/performance/subversion/libsvn_subr/svn_string.c Wed Oct
27 20:47:06 2010
@@ -266,9 +266,21 @@ 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);
+ 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. */
+ apr_size_t aligned_size = APR_ALIGN_DEFAULT(size + 1) - 1;
+
+ /* Ensure string buffer of aligned_size + 1.
+ * This should allocate the same amount of memory as "size" would. */
+ svn_stringbuf_t *strbuf = svn_stringbuf_create_ensure(aligned_size, pool);
+
+ /* Actually, aligned_size+1 would be faster but we cannot be entirely
+ * sure that the source string has been aligned properly such that
+ * all the extra bytes would actually come from addressible memory.*/
memcpy(strbuf->data, bytes, size);
/* Null termination is the convention -- even if we suspect the data