From: Julian Seward Date: Fri, 22 Aug 2008 23:16:06 +0000 (+0000) Subject: Try and bit a bit more space-economical, by increasing the X-Git-Tag: svn/VALGRIND_3_4_0~282 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6136f591bae849215b43014af4ba09cacf48cc35;p=thirdparty%2Fvalgrind.git Try and bit a bit more space-economical, by increasing the average loading factor from 0.75 to 0.83, and by being more careful in VG_(cloneXA). git-svn-id: svn://svn.valgrind.org/valgrind/trunk@8539 --- diff --git a/coregrind/m_xarray.c b/coregrind/m_xarray.c index 19130100ba..1b859941f2 100644 --- a/coregrind/m_xarray.c +++ b/coregrind/m_xarray.c @@ -91,6 +91,13 @@ XArray* VG_(cloneXA)( XArray* xao ) *nyu = *xa; /* ... except we have to clone the contents-array */ if (nyu->arr) { + /* Restrict the total size of the new array to its current + actual size. That means we don't waste space copying the + unused tail of the original. The tradeoff is that it + guarantees we will have to resize the child if even one more + element is later added to it, unfortunately. */ + nyu->totsizeE = nyu->usedsizeE; + /* and allocate .. */ nyu->arr = nyu->alloc( nyu->totsizeE * nyu->elemSzB ); if (!nyu->arr) { nyu->free(nyu); @@ -149,9 +156,9 @@ static inline void ensureSpaceXA ( struct _XArray* xa ) else if (xa->elemSzB == 2) newsz = 4; else newsz = 2; } else { - newsz = 2 * xa->totsizeE; + newsz = 1 + (3 * xa->totsizeE) / 2; /* 2 * xa->totsizeE; */ } - if (0) + if (0 && xa->totsizeE >= 10000) VG_(printf)("addToXA: increasing from %ld to %ld\n", xa->totsizeE, newsz); tmp = xa->alloc(newsz * xa->elemSzB);