Author: sewardj
Date: 2008-02-14 16:55:01 +0000 (Thu, 14 Feb 2008)
New Revision: 7408

Log:
More performance tuning (mostly pointless).


Modified:
   branches/DATASYMS/coregrind/m_debuginfo/misc.c
   branches/DATASYMS/coregrind/m_debuginfo/priv_misc.h
   branches/DATASYMS/coregrind/m_debuginfo/readdwarf3.c
   branches/DATASYMS/coregrind/m_debuginfo/tytypes.c
   branches/DATASYMS/coregrind/m_xarray.c
   branches/DATASYMS/include/pub_tool_xarray.h


Modified: branches/DATASYMS/coregrind/m_debuginfo/misc.c
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/misc.c      2008-02-14 12:09:04 UTC 
(rev 7407)
+++ branches/DATASYMS/coregrind/m_debuginfo/misc.c      2008-02-14 16:55:01 UTC 
(rev 7408)
@@ -60,14 +60,6 @@
 }
 
 
-void ML_(copy_bytes_into_XA) ( XArray* /* of UChar */ xa, 
-                               void* bytes, Word nbytes ) {
-   Word i;
-   for (i = 0; i < nbytes; i++)
-      VG_(addToXA)( xa, & ((UChar*)bytes)[i] );
-}
-
-
 /*--------------------------------------------------------------------*/
 /*--- end                                                   misc.c ---*/
 /*--------------------------------------------------------------------*/

Modified: branches/DATASYMS/coregrind/m_debuginfo/priv_misc.h
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/priv_misc.h 2008-02-14 12:09:04 UTC 
(rev 7407)
+++ branches/DATASYMS/coregrind/m_debuginfo/priv_misc.h 2008-02-14 16:55:01 UTC 
(rev 7408)
@@ -51,10 +51,6 @@
 void   ML_(dinfo_free)( void* v );
 UChar* ML_(dinfo_strdup)( const UChar* str );
 
-/* Copy bytes into an XArray of what are assumed to be, well,
-   bytes. */
-void ML_(copy_bytes_into_XA) ( XArray* /* of UChar */ xa, 
-                               void* bytes, Word nbytes );
 
 #endif /* ndef __PRIV_MISC_H */
 

Modified: branches/DATASYMS/coregrind/m_debuginfo/readdwarf3.c
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/readdwarf3.c        2008-02-14 
12:09:04 UTC (rev 7407)
+++ branches/DATASYMS/coregrind/m_debuginfo/readdwarf3.c        2008-02-14 
16:55:01 UTC (rev 7408)
@@ -499,7 +499,7 @@
    xa = VG_(newXA)( ML_(dinfo_zalloc), ML_(dinfo_free),
                     sizeof(UChar) );
 
-   { UChar c = 1; /*biasMe*/ VG_(addToXA)( xa, &c ); }
+   { UChar c = 1; /*biasMe*/ VG_(addBytesToXA)( xa, &c, sizeof(c) ); }
 
    base = 0;
    while (True) {
@@ -536,26 +536,26 @@
          UShort s;
          UChar  c;
          c = 0; /* !isEnd*/
-         VG_(addToXA)( xa, &c );
+         VG_(addBytesToXA)( xa, &c, sizeof(c) );
          w = w1    + base + svma_of_referencing_CU;
-         ML_(copy_bytes_into_XA)( xa, &w, sizeof(w) );
+         VG_(addBytesToXA)( xa, &w, sizeof(w) );
          w = w2 -1 + base + svma_of_referencing_CU;
-         ML_(copy_bytes_into_XA)( xa, &w, sizeof(w) );
+         VG_(addBytesToXA)( xa, &w, sizeof(w) );
          s = (UShort)len;
-         ML_(copy_bytes_into_XA)( xa, &s, sizeof(s) );
+         VG_(addBytesToXA)( xa, &s, sizeof(s) );
       }
 
       while (len > 0) {
          UChar byte = get_UChar( &loc );
          TRACE_D3("%02x", (UInt)byte);
          if (acquire)
-            VG_(addToXA)( xa, &byte );
+            VG_(addBytesToXA)( xa, &byte, 1 );
          len--;
       }
       TRACE_D3("\n");
    }
 
-   { UChar c = 1; /*isEnd*/ VG_(addToXA)( xa, &c ); }
+   { UChar c = 1; /*isEnd*/ VG_(addBytesToXA)( xa, &c, sizeof(c) ); }
 
    nbytes = VG_(sizeXA)( xa );
    vg_assert(nbytes >= 1);

Modified: branches/DATASYMS/coregrind/m_debuginfo/tytypes.c
===================================================================
--- branches/DATASYMS/coregrind/m_debuginfo/tytypes.c   2008-02-14 12:09:04 UTC 
(rev 7407)
+++ branches/DATASYMS/coregrind/m_debuginfo/tytypes.c   2008-02-14 16:55:01 UTC 
(rev 7408)
@@ -402,7 +402,7 @@
    UChar buf[32];
    VG_(memset)(buf, 0, sizeof(buf));
    VG_(sprintf)(buf, "%lu", uw);
-   ML_(copy_bytes_into_XA)( xa, buf, VG_(strlen)(buf));
+   VG_(addBytesToXA)( xa, buf, VG_(strlen)(buf));
 }
 
 /* Describe where in the type 'offset' falls.  Caller must
@@ -455,9 +455,9 @@
                goto done; /* No.  Give up. */
             /* Yes.  'field' is it. */
             if (!field->name) goto done;
-            ML_(copy_bytes_into_XA)( xa, ".", 1 );
-            ML_(copy_bytes_into_XA)( xa, field->name,
-                                     VG_(strlen)(field->name) );
+            VG_(addBytesToXA)( xa, ".", 1 );
+            VG_(addBytesToXA)( xa, field->name,
+                               VG_(strlen)(field->name) );
             offset -= offMin;
             ty = field->typeR;
             if (!ty) goto done;
@@ -484,9 +484,9 @@
             eszB = ML_(sizeOfType)( ty->Ty.Array.typeR );
             if (eszB == 0) goto done;
             ix = offset / eszB;
-            ML_(copy_bytes_into_XA)( xa, "[", 1 );
+            VG_(addBytesToXA)( xa, "[", 1 );
             copy_UWord_into_XA( xa, ix );
-            ML_(copy_bytes_into_XA)( xa, "]", 1 );
+            VG_(addBytesToXA)( xa, "]", 1 );
             ty = ty->Ty.Array.typeR;
             offset -= ix * eszB;
             /* keep going; look inside the array element. */
@@ -516,7 +516,7 @@
 
   done:
    *residual_offset = offset;
-   ML_(copy_bytes_into_XA)( xa, "\0", 1 );
+   VG_(addBytesToXA)( xa, "\0", 1 );
    return xa;
 }
 

Modified: branches/DATASYMS/coregrind/m_xarray.c
===================================================================
--- branches/DATASYMS/coregrind/m_xarray.c      2008-02-14 12:09:04 UTC (rev 
7407)
+++ branches/DATASYMS/coregrind/m_xarray.c      2008-02-14 16:55:01 UTC (rev 
7408)
@@ -104,13 +104,8 @@
    return ((char*)xa->arr) + n * xa->elemSzB;
 }
 
-Int VG_(addToXA) ( XArray* xao, void* elem )
+static inline void ensureSpaceXA ( struct _XArray* xa )
 {
-   struct _XArray* xa = (struct _XArray*)xao;
-   vg_assert(xa);
-   vg_assert(elem);
-   vg_assert(xa->totsizeE >= 0);
-   vg_assert(xa->usedsizeE >= 0 && xa->usedsizeE <= xa->totsizeE);
    if (xa->usedsizeE == xa->totsizeE) {
       void* tmp;
       Word  newsz;
@@ -142,20 +137,46 @@
       xa->arr = tmp;
       xa->totsizeE = newsz;
    }
+}
+
+Int VG_(addToXA) ( XArray* xao, void* elem )
+{
+   struct _XArray* xa = (struct _XArray*)xao;
+   vg_assert(xa);
+   vg_assert(elem);
+   vg_assert(xa->totsizeE >= 0);
+   vg_assert(xa->usedsizeE >= 0 && xa->usedsizeE <= xa->totsizeE);
+   ensureSpaceXA( xa );
    vg_assert(xa->usedsizeE < xa->totsizeE);
    vg_assert(xa->arr);
-   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 );
-   }
+   VG_(memcpy)( ((UChar*)xa->arr) + xa->usedsizeE * xa->elemSzB,
+                elem, xa->elemSzB );
    xa->usedsizeE++;
    xa->sorted = False;
    return xa->usedsizeE-1;
 }
 
+Int VG_(addBytesToXA) ( XArray* xao, void* bytesV, Int nbytes )
+{
+   Int r, i;
+   struct _XArray* xa = (struct _XArray*)xao;
+   vg_assert(xa);
+   vg_assert(xa->elemSzB == 1);
+   vg_assert(nbytes >= 0);
+   vg_assert(xa->totsizeE >= 0);
+   vg_assert(xa->usedsizeE >= 0 && xa->usedsizeE <= xa->totsizeE);
+   r = xa->usedsizeE;
+   for (i = 0; i < nbytes; i++) {
+      ensureSpaceXA( xa );
+      vg_assert(xa->usedsizeE < xa->totsizeE);
+      vg_assert(xa->arr);
+      * (((UChar*)xa->arr) + xa->usedsizeE) = ((UChar*)bytesV)[i];
+      xa->usedsizeE++;
+   }
+   xa->sorted = False;
+   return r;
+}
+
 void VG_(sortXA) ( XArray* xao )
 {
    struct _XArray* xa = (struct _XArray*)xao;

Modified: branches/DATASYMS/include/pub_tool_xarray.h
===================================================================
--- branches/DATASYMS/include/pub_tool_xarray.h 2008-02-14 12:09:04 UTC (rev 
7407)
+++ branches/DATASYMS/include/pub_tool_xarray.h 2008-02-14 16:55:01 UTC (rev 
7408)
@@ -66,6 +66,11 @@
    invalidated if the array is later sortXA'd. */
 extern Int VG_(addToXA) ( XArray*, void* elem );
 
+/* Add a sequence of bytes to an XArray of bytes.  Asserts if nbytes
+   is negative or the array's element size is not 1.  Returns the
+   index at which the first byte was added. */
+extern Int VG_(addBytesToXA) ( XArray* xao, void* bytesV, Int nbytes );
+
 /* Sort an XArray using its comparison function, if set; else bomb.
    Probably not a stable sort w.r.t. equal elements module cmpFn. */
 extern void VG_(sortXA) ( XArray* );


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to