]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Remove duplicate code -- make XArray use VG_(ssort).
authorNicholas Nethercote <njn@valgrind.org>
Wed, 28 Mar 2007 01:27:05 +0000 (01:27 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Wed, 28 Mar 2007 01:27:05 +0000 (01:27 +0000)
Had to change XArray's comparison function to return an Int rather than a
Word so it's consistent with the rest of the world.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6680

coregrind/m_debuginfo/readxcoff.c
coregrind/m_xarray.c
include/pub_tool_xarray.h

index 2e3c01fa2ea63c36a8f56584ce9d93518a84b102..769937ccd577ba959fab4a5e9e00ce98ddce1af9 100644 (file)
@@ -262,7 +262,7 @@ static Bool eq_string_Name ( Name name, UChar* str )
       return False;
 }
 
-static Word cmp_Names ( Name n1, Name n2 )
+static Int cmp_Names ( Name n1, Name n2 )
 {
    UInt i = 0;
    while (1) {
@@ -384,7 +384,7 @@ static void init_XCoffSym( XCoffSym* sym )
 }
 
 /* Compare XCoffSyms by their start address. */
-static Word cmp_XCoffSym_by_start ( void* v1, void* v2 )
+static Int cmp_XCoffSym_by_start ( void* v1, void* v2 )
 {
    XCoffSym* s1 = (XCoffSym*)v1;
    XCoffSym* s2 = (XCoffSym*)v2;
@@ -395,7 +395,7 @@ static Word cmp_XCoffSym_by_start ( void* v1, void* v2 )
 
 /* Compare XCoffSyms by a slightly weaker ordering, returning zero
    (equivalence) for any overlap, and -1 or 1 otherwise. */
-static Word cmp_XCoffSym_by_overlap ( void* v1, void* v2 )
+static Int cmp_XCoffSym_by_overlap ( void* v1, void* v2 )
 {
    XCoffSym* s1 = (XCoffSym*)v1;
    XCoffSym* s2 = (XCoffSym*)v2;
@@ -406,7 +406,7 @@ static Word cmp_XCoffSym_by_overlap ( void* v1, void* v2 )
 
 /* Compare XCoffSyms by their start address, and for equal addresses,
    use the name as a secondary sort key. */
-static Word cmp_XCoffSym_by_start_then_name ( void* v1, void* v2 )
+static Int cmp_XCoffSym_by_start_then_name ( void* v1, void* v2 )
 {
    XCoffSym* s1 = (XCoffSym*)v1;
    XCoffSym* s2 = (XCoffSym*)v2;
index 09dc628ee1f203938da95cae3881abeeb83a4f52..3f7628c570e7ab5d7149d250a2cc801b67b38a6e 100644 (file)
@@ -40,7 +40,7 @@
 struct _XArray {
    void* (*alloc) ( SizeT );        /* alloc fn (nofail) */
    void  (*free) ( void* );         /* free fn */
-   Word  (*cmpFn) ( void*, void* ); /* cmp fn (may be NULL) */
+   Int   (*cmpFn) ( void*, void* ); /* cmp fn (may be NULL) */
    Word  elemSzB;   /* element size in bytes */
    void* arr;       /* pointer to elements */
    Word  usedsizeE; /* # used elements in arr */
@@ -86,7 +86,7 @@ void VG_(deleteXA) ( XArray* xao )
    xa->free(xa);
 }
 
-void VG_(setCmpFnXA) ( XArray* xao, Word (*compar)(void*,void*) )
+void VG_(setCmpFnXA) ( XArray* xao, Int (*compar)(void*,void*) )
 {
    struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
@@ -140,60 +140,12 @@ Int VG_(addToXA) ( XArray* xao, void* elem )
    return xa->usedsizeE-1;
 }
 
-// Generic shell sort.  Like stdlib.h's qsort().
-static void ssort( void* base, Word nmemb, Word size,
-                   Word (*compar)(void*, void*) )
-{
-   Int   incs[14] = { 1, 4, 13, 40, 121, 364, 1093, 3280,
-                      9841, 29524, 88573, 265720,
-                      797161, 2391484 };
-   Int   lo = 0;
-   Int   hi = nmemb-1;
-   Int   i, j, h, bigN, hp;
-
-   bigN = hi - lo + 1; if (bigN < 2) return;
-   hp = 0; while (hp < 14 && incs[hp] < bigN) hp++; hp--;
-
-   #define SORT \
-   for ( ; hp >= 0; hp--) { \
-      h = incs[hp]; \
-      for (i = lo + h; i <= hi; i++) { \
-         ASSIGN(v,0, a,i); \
-         j = i; \
-         while (COMPAR(a,(j-h), v,0) > 0) { \
-            ASSIGN(a,j, a,(j-h)); \
-            j = j - h; \
-            if (j <= (lo + h - 1)) break; \
-         } \
-         ASSIGN(a,j, v,0); \
-      } \
-   }
-
-   // General case
-   {
-      char* a = base;
-      char  v[size];      // will be at least 'size' bytes
-
-      #define ASSIGN(dst, dsti, src, srci) \
-      VG_(memcpy)( &dst[size*(dsti)], &src[size*(srci)], size );
-
-      #define COMPAR(dst, dsti, src, srci) \
-      compar( &dst[size*(dsti)], &src[size*(srci)] )
-
-      SORT;
-
-      #undef ASSIGN
-      #undef COMPAR
-   }
-   #undef SORT
-}
-
 void VG_(sortXA) ( XArray* xao )
 {
    struct _XArray* xa = (struct _XArray*)xao;
    vg_assert(xa);
    vg_assert(xa->cmpFn);
-   ssort( xa->arr, xa->usedsizeE, xa->elemSzB, xa->cmpFn );
+   VG_(ssort)( xa->arr, xa->usedsizeE, xa->elemSzB, xa->cmpFn );
    xa->sorted = True;
 }
 
index 234be204f21d515c8b026f377720b2d50bd0abd0..4b97f727578bd2ffcf6017185f7833e841b669e9 100644 (file)
@@ -59,7 +59,7 @@ extern void VG_(deleteXA) ( XArray* );
 /* Set the comparison function for this XArray.  This clears an
    internal 'array is sorted' flag, which means you must call sortXA
    before making further queries with lookupXA. */
-extern void VG_(setCmpFnXA) ( XArray*, Word (*compar)(void*,void*) );
+extern void VG_(setCmpFnXA) ( XArray*, Int (*compar)(void*,void*) );
 
 /* Add an element to an XArray.  Element is copied into the XArray.
    Index at which it was added is returned.  Note this will be