|
From: <sv...@va...> - 2007-03-28 01:27:07
|
Author: njn
Date: 2007-03-28 02:27:05 +0100 (Wed, 28 Mar 2007)
New Revision: 6680
Log:
Remove duplicate code -- make XArray use VG_(ssort).
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.
Modified:
trunk/coregrind/m_debuginfo/readxcoff.c
trunk/coregrind/m_xarray.c
trunk/include/pub_tool_xarray.h
Modified: trunk/coregrind/m_debuginfo/readxcoff.c
===================================================================
--- trunk/coregrind/m_debuginfo/readxcoff.c 2007-03-27 23:40:46 UTC (rev 6679)
+++ trunk/coregrind/m_debuginfo/readxcoff.c 2007-03-28 01:27:05 UTC (rev 6680)
@@ -262,7 +262,7 @@
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 @@
}
/* 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 @@
/* 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 @@
/* 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;
Modified: trunk/coregrind/m_xarray.c
===================================================================
--- trunk/coregrind/m_xarray.c 2007-03-27 23:40:46 UTC (rev 6679)
+++ trunk/coregrind/m_xarray.c 2007-03-28 01:27:05 UTC (rev 6680)
@@ -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 @@
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 @@
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;
}
Modified: trunk/include/pub_tool_xarray.h
===================================================================
--- trunk/include/pub_tool_xarray.h 2007-03-27 23:40:46 UTC (rev 6679)
+++ trunk/include/pub_tool_xarray.h 2007-03-28 01:27:05 UTC (rev 6680)
@@ -59,7 +59,7 @@
/* 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
|