ICU-21526 Change return of UElementComparator to int32_t

See 
This commit is contained in:
Frank Tang 2021-03-31 05:36:55 +00:00 committed by Frank Yung-Fong Tang
parent 05b20c1ccb
commit bdb4c7025a
7 changed files with 16 additions and 28 deletions

View file

@ -48,7 +48,7 @@ static void _fb_trace(const char *m, const UnicodeString *s, UBool b, int32_t d,
/**
* Used with sortedInsert()
*/
static int8_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) {
static int32_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) {
const UnicodeString &a = *(const UnicodeString*)t1.pointer;
const UnicodeString &b = *(const UnicodeString*)t2.pointer;
return a.compare(b);

View file

@ -1578,13 +1578,8 @@ AliasReplacer::replaceTransformedExtensions(
}
tkey = nextTKey;
} while (tkey != nullptr);
tfields.sort([](UElement e1, UElement e2) -> int8_t {
// uprv_strcmp return int and in some platform, such as arm64-v8a,
// it may return positive values > 127 which cause the casted value
// of int8_t negative.
int res = uprv_strcmp(
(const char*)e1.pointer, (const char*)e2.pointer);
return (res == 0) ? 0 : ((res > 0) ? 1 : -1);
tfields.sort([](UElement e1, UElement e2) -> int32_t {
return uprv_strcmp((const char*)e1.pointer, (const char*)e2.pointer);
}, status);
for (int32_t i = 0; i < tfields.size(); i++) {
if (output.length() > 0) {
@ -1623,13 +1618,8 @@ AliasReplacer::outputToString(
if (!notEmpty(script) && !notEmpty(region)) {
out.append(SEP_CHAR, status);
}
variants.sort([](UElement e1, UElement e2) -> int8_t {
// uprv_strcmp return int and in some platform, such as arm64-v8a,
// it may return positive values > 127 which cause the casted value
// of int8_t negative.
int res = uprv_strcmp(
(const char*)e1.pointer, (const char*)e2.pointer);
return (res == 0) ? 0 : ((res > 0) ? 1 : -1);
variants.sort([](UElement e1, UElement e2) -> int32_t {
return uprv_strcmp((const char*)e1.pointer, (const char*)e2.pointer);
}, status);
int32_t variantsStart = out.length();
for (int32_t i = 0; i < variants.size(); i++) {
@ -1689,13 +1679,8 @@ AliasReplacer::replace(const Locale& locale, CharString& out, UErrorCode& status
if (U_FAILURE(status)) { return false; }
// Sort the variants
variants.sort([](UElement e1, UElement e2) -> int8_t {
// uprv_strcmp return int and in some platform, such as arm64-v8a,
// it may return positive values > 127 which cause the casted value
// of int8_t negative.
int res = uprv_strcmp(
(const char*)e1.pointer, (const char*)e2.pointer);
return (res == 0) ? 0 : ((res > 0) ? 1 : -1);
variants.sort([](UElement e1, UElement e2) -> int32_t {
return uprv_strcmp((const char*)e1.pointer, (const char*)e2.pointer);
}, status);
// A changed count to assert when loop too many times.

View file

@ -54,9 +54,12 @@ typedef UBool U_CALLCONV UElementsAreEqual(const UElement e1, const UElement e2)
* An element sorting (three-way) comparison function.
* @param e1 An element (object or integer)
* @param e2 An element (object or integer)
* @return 0 if the two elements are equal, -1 if e1 is < e2, or +1 if e1 is > e2.
* @return 32-bit signed integer comparison result:
* ==0 if the two elements are equal,
* <0 if e1 is < e2, or
* >0 if e1 is > e2.
*/
typedef int8_t U_CALLCONV UElementComparator(UElement e1, UElement e2);
typedef int32_t U_CALLCONV UElementComparator(UElement e1, UElement e2);
/**
* An element assignment function. It may copy an integer, copy

View file

@ -111,7 +111,7 @@ static void U_CALLCONV cloneUnicodeString(UElement *dst, UElement *src) {
dst->pointer = new UnicodeString(*(UnicodeString*)src->pointer);
}
static int8_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) {
static int32_t U_CALLCONV compareUnicodeString(UElement t1, UElement t2) {
const UnicodeString &a = *(const UnicodeString*)t1.pointer;
const UnicodeString &b = *(const UnicodeString*)t2.pointer;
return a.compare(b);

View file

@ -466,7 +466,7 @@ void UVector::sortedInsert(UElement e, UElementComparator *compare, UErrorCode&
int32_t min = 0, max = count;
while (min != max) {
int32_t probe = (min + max) / 2;
int8_t c = (*compare)(elements[probe], e);
int32_t c = (*compare)(elements[probe], e);
if (c > 0) {
max = probe;
} else {

View file

@ -113,7 +113,7 @@ SPUString *SPUStringPool::getByIndex(int32_t index) {
// by code point order.
// Conforms to the type signature for a USortComparator in uvector.h
static int8_t U_CALLCONV SPUStringCompare(UHashTok left, UHashTok right) {
static int32_t U_CALLCONV SPUStringCompare(UHashTok left, UHashTok right) {
const SPUString *sL = const_cast<const SPUString *>(
static_cast<SPUString *>(left.pointer));
const SPUString *sR = const_cast<const SPUString *>(

View file

@ -70,7 +70,7 @@ void UVectorTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
}\
} UPRV_BLOCK_MACRO_END
static int8_t U_CALLCONV
static int32_t U_CALLCONV
UVectorTest_compareInt32(UElement key1, UElement key2) {
if (key1.integer > key2.integer) {
return 1;