]> granicus.if.org Git - icu/commitdiff
ICU-10291 Optimize IDNA toASCII loop
authorFrank Tang <ftang@chromium.org>
Tue, 12 Mar 2019 20:12:54 +0000 (13:12 -0700)
committerFrank Yung-Fong Tang <41213225+FrankYFTang@users.noreply.github.com>
Wed, 13 Mar 2019 19:13:42 +0000 (12:13 -0700)
icu4c/source/common/uidna.cpp
icu4j/main/classes/core/src/com/ibm/icu/impl/IDNA2003.java

index 7cc97a93a01459d120c1d6d6f8f67e20eac571c2..ac2f9c3c8cd96388509e714e12f7ea1b15d6fa00 100644 (file)
@@ -57,18 +57,16 @@ toASCIILower(UChar ch){
 
 inline static UBool 
 startsWithPrefix(const UChar* src , int32_t srcLength){
-    UBool startsWithPrefix = TRUE;
-
     if(srcLength < ACE_PREFIX_LENGTH){
         return FALSE;
     }
 
     for(int8_t i=0; i< ACE_PREFIX_LENGTH; i++){
         if(toASCIILower(src[i]) != ACE_PREFIX[i]){
-            startsWithPrefix = FALSE;
+            return FALSE;
         }
     }
-    return startsWithPrefix;
+    return TRUE;
 }
 
 
@@ -441,6 +439,7 @@ _internal_toUnicode(const UChar* src, int32_t srcLength,
         for(int32_t j=0; j<srcLength; j++){
             if(src[j]> 0x7f){
                 srcIsASCII = FALSE;
+                break;
             }/*else if(isLDHChar(src[j])==FALSE){
                 // here we do not assemble surrogates
                 // since we know that LDH code points
index e3503b87ba4dc8a11414d0873ed226bf25c4053b..12ba5a97c1edaf1bbf3448024a293b75d2bc3bc4 100644 (file)
@@ -35,17 +35,15 @@ public final class IDNA2003 {
     private static final StringPrep namePrep = StringPrep.getInstance(StringPrep.RFC3491_NAMEPREP);
     
     private static boolean startsWithPrefix(StringBuffer src){
-        boolean startsWithPrefix = true;
-
         if(src.length() < ACE_PREFIX.length){
             return false;
         }
         for(int i=0; i<ACE_PREFIX.length;i++){
             if(toASCIILower(src.charAt(i)) != ACE_PREFIX[i]){
-                startsWithPrefix = false;
+                return false;
             }
         }
-        return startsWithPrefix;
+        return true;
     }
 
     private static char toASCIILower(char ch){
@@ -168,6 +166,7 @@ public final class IDNA2003 {
         while((ch = src.next())!= UCharacterIterator.DONE){
             if(ch> 0x7f){
                 srcIsASCII = false;
+                break;
             }
         }
         int failPos = -1;