ICU-2235 leave the string table in data.h order so that swapping need not resort it, and swapping testing can still test for identity

X-SVN-Rev: 13222
This commit is contained in:
Markus Scherer 2003-09-26 20:50:41 +00:00
parent c3f04bcdcc
commit 07111b3ca9

View file

@ -9,13 +9,13 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include "unicode/utypes.h"
#include "unicode/putil.h"
#include "unicode/uclean.h"
#include "cmemory.h"
#include "cstring.h"
#include "filestrm.h"
#include "uarrsort.h"
#include "unewdata.h"
#include "uoptions.h"
#include "uprops.h"
@ -215,9 +215,12 @@ public:
NameToEnumEntry(int32_t a, int32_t b) { nameIndex=a; enumValue=b; }
};
// Sort function for NameToEnumEntry (sort by name index)
U_CAPI int compareNameToEnumEntry(const void* e1, const void* e2) {
return ((NameToEnumEntry*)e1)->nameIndex - ((NameToEnumEntry*)e2)->nameIndex;
// Sort function for NameToEnumEntry (sort by name)
U_CAPI int32_t
compareNameToEnumEntry(const void * /*context*/, const void* e1, const void* e2) {
return
STRING_TABLE[((NameToEnumEntry*)e1)->nameIndex].
compare(STRING_TABLE[((NameToEnumEntry*)e2)->nameIndex]);
}
//----------------------------------------------------------------------
@ -246,7 +249,8 @@ public:
};
// Sort function for EnumToNameGroupEntry (sort by name index)
U_CAPI int compareEnumToNameGroupEntry(const void* e1, const void* e2) {
U_CAPI int32_t
compareEnumToNameGroupEntry(const void * /*context*/, const void* e1, const void* e2) {
return ((EnumToNameGroupEntry*)e1)->enumValue - ((EnumToNameGroupEntry*)e2)->enumValue;
}
@ -277,7 +281,8 @@ public:
};
// Sort function for EnumToValueEntry (sort by enum)
U_CAPI int compareEnumToValueEntry(const void* e1, const void* e2) {
U_CAPI int32_t
compareEnumToValueEntry(const void * /*context*/, const void* e1, const void* e2) {
return ((EnumToValueEntry*)e1)->enumValue - ((EnumToValueEntry*)e2)->enumValue;
}
@ -898,11 +903,6 @@ static UDataInfo dataInfo = {
{VERSION_0, VERSION_1, VERSION_2, VERSION_3} /* Unicode version */
};
// Glue for C<->C++
U_CAPI int compareAliasNames(const void* elem1, const void* elem2) {
return ((const AliasName*)elem1)->compare(*(const AliasName*)elem2);
}
class genpname {
// command-line options
@ -977,8 +977,14 @@ NameToEnumEntry* genpname::createNameIndex(const AliasList& list,
NameToEnumEntry(names[j], p.enumValue);
}
}
qsort((void*) nameIndex, nameIndexCount, sizeof(nameIndex[0]),
compareNameToEnumEntry);
/*
* use a stable sort to ensure consistent results between
* genpname.cpp and the propname.cpp swapping code
*/
UErrorCode errorCode = U_ZERO_ERROR;
uprv_sortArray(nameIndex, nameIndexCount, sizeof(nameIndex[0]),
compareNameToEnumEntry, NULL, TRUE, &errorCode);
if (debug>1) {
printf("Alias names: %d\n", nameIndexCount);
for (i=0; i<nameIndexCount; ++i) {
@ -1029,8 +1035,10 @@ EnumToNameGroupEntry* genpname::createEnumIndex(const AliasList& list) {
const Alias& p = list[i];
enumIndex[i] = EnumToNameGroupEntry(p.enumValue, p.nameGroupIndex);
}
qsort((void*) enumIndex, count, sizeof(enumIndex[0]),
compareEnumToNameGroupEntry);
UErrorCode errorCode = U_ZERO_ERROR;
uprv_sortArray(enumIndex, count, sizeof(enumIndex[0]),
compareEnumToNameGroupEntry, NULL, FALSE, &errorCode);
if (debug>1) {
printf("Property enums: %d\n", count);
for (i=0; i<count; ++i) {
@ -1099,35 +1107,22 @@ int genpname::MMain(int argc, char* argv[])
verbose = options[4].doesOccur;
// ------------------------------------------------------------
// Sort the string table. This produces the proper sorting
// using the actual comparison function we will use.
qsort((void*) STRING_TABLE, STRING_COUNT, sizeof(STRING_TABLE[0]),
compareAliasNames);
// Do not sort the string table, instead keep it in data.h order.
// This simplifies data swapping and testing thereof because the string
// table itself need not be sorted during swapping.
// The NameToEnum sorter sorts each such map's string offsets instead.
if (debug>1) {
printf("String pool: %d\n", STRING_COUNT);
}
for (i=0; i<STRING_COUNT; ++i) {
REMAP[STRING_TABLE[i].index] = i;
if (debug>1) {
if (i != 0) printf(", ");
for (i=0; i<STRING_COUNT; ++i) {
if (i != 0) {
printf(", ");
}
printf("%s (%d)", STRING_TABLE[i].str, STRING_TABLE[i].index);
}
}
if (debug>1) {
printf("\n\n");
}
// ------------------------------------------------------------
// Fixup the NAME_GROUP indices so they match the sorted order
for (i=0; i<NAME_GROUP_COUNT; ++i) {
// keep negative entries (end markers) negative
if (NAME_GROUP[i] < 0) {
NAME_GROUP[i] = -REMAP[-NAME_GROUP[i]];
} else {
NAME_GROUP[i] = REMAP[NAME_GROUP[i]];
}
}
// ------------------------------------------------------------
// Create top-level property indices
@ -1154,8 +1149,9 @@ int genpname::MMain(int argc, char* argv[])
++j;
}
enumToValue_count = j;
qsort((void*) enumToValue, enumToValue_count, sizeof(enumToValue[0]),
compareEnumToValueEntry);
uprv_sortArray(enumToValue, enumToValue_count, sizeof(enumToValue[0]),
compareEnumToValueEntry, NULL, FALSE, &status);
// ------------------------------------------------------------
// Build PropertyAliases layout in memory