ICU-21526 Change return of UElementComparator to int32_t
authorFrank Tang <ftang@chromium.org>
Wed, 31 Mar 2021 05:36:55 +0000 (05:36 +0000)
committerFrank Yung-Fong Tang <ftang@google.com>
Wed, 31 Mar 2021 19:02:08 +0000 (12:02 -0700)
See #1621

icu4c/source/common/filteredbrk.cpp
icu4c/source/common/locid.cpp
icu4c/source/common/uelement.h
icu4c/source/common/uniset.cpp
icu4c/source/common/uvector.cpp
icu4c/source/i18n/uspoof_conf.cpp
icu4c/source/test/intltest/uvectest.cpp

index c07128cbce10e116aae88cd645d335b05c9f7e64..d2a6d9832708e119931af5a978d329c1b912d2dd 100644 (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);
index 3dcc5bcfa8a607dbc2292282b440497aefb18de5..8f1b22c26d158c8d6c5aa5ea8989087af2478359 100644 (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.
index 88dd4d66fb992cb412e136666b6a2d8dd2eb958d..2c5a2043e17d5b129ba3782cb4744e7c769df3b7 100644 (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
index 461e5a7197e724ef2175a73d15ddc10b0fad8ca0..2db45a2b2a84028b493d2a9a14a8509b845ead31 100644 (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);
index 9c7e74c6d5af52b041e356b6b2d1594a022c9878..fd53c603456a813c52bca8e670353a2a5bc06657 100644 (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 {
index 862f5daef5dbfdcbc92a6dbd53617243614ec08e..acb7332b10dec928bd8f0fe988b5354d83275b6b 100644 (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 *>(
index 3829ba2668d896b979f943a4450a12c723d9dae2..0a05ea9f59d63693c90708cb25cc69997466288e 100644 (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;