]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Try and bit a bit more space-economical, by increasing the
authorJulian Seward <jseward@acm.org>
Fri, 22 Aug 2008 23:16:06 +0000 (23:16 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 22 Aug 2008 23:16:06 +0000 (23:16 +0000)
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

coregrind/m_xarray.c

index 19130100baca214755f79583576ce9b23c22acdc..1b859941f2eac42c1ce96dfe22c9f60b35a59fa0 100644 (file)
@@ -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);