|
From: <sv...@va...> - 2008-02-07 11:48:22
|
Author: sewardj
Date: 2008-02-07 11:48:24 +0000 (Thu, 07 Feb 2008)
New Revision: 7372
Log:
Be somewhat more efficient when the element type is very small (eg char).
Modified:
branches/DATASYMS/coregrind/m_xarray.c
Modified: branches/DATASYMS/coregrind/m_xarray.c
===================================================================
--- branches/DATASYMS/coregrind/m_xarray.c 2008-02-05 20:07:23 UTC (rev 7371)
+++ branches/DATASYMS/coregrind/m_xarray.c 2008-02-07 11:48:24 UTC (rev 7372)
@@ -118,7 +118,18 @@
vg_assert(!xa->arr);
if (xa->totsizeE > 0)
vg_assert(xa->arr);
- newsz = xa->totsizeE==0 ? 2 : 2 * xa->totsizeE;
+ if (xa->totsizeE == 0) {
+ /* No point in having tiny (eg) 2-byte allocations for the
+ element array, since all allocs are rounded up to 8 anyway.
+ Hence increase the initial array size for tiny elements in
+ an attempt to avoid reallocations of size 2, 4, 8 if the
+ array does start to fill up. */
+ if (xa->elemSzB == 1) newsz = 8;
+ else if (xa->elemSzB == 2) newsz = 4;
+ else newsz = 2;
+ } else {
+ newsz = 2 * xa->totsizeE;
+ }
if (0)
VG_(printf)("addToXA: increasing from %ld to %ld\n",
xa->totsizeE, newsz);
@@ -133,8 +144,13 @@
}
vg_assert(xa->usedsizeE < xa->totsizeE);
vg_assert(xa->arr);
- VG_(memcpy)( ((UChar*)xa->arr) + xa->usedsizeE * xa->elemSzB,
- elem, xa->elemSzB );
+ if (xa->elemSzB == 1) {
+ /* calling memcpy is just stupid, hence */
+ * (((UChar*)xa->arr) + xa->usedsizeE) = * ((UChar*) elem);
+ } else {
+ VG_(memcpy)( ((UChar*)xa->arr) + xa->usedsizeE * xa->elemSzB,
+ elem, xa->elemSzB );
+ }
xa->usedsizeE++;
xa->sorted = False;
return xa->usedsizeE-1;
|