changeset 1422:e0707baa1593

6792400: Avoid loading of Normalizer resources for simple uses Reviewed-by: okutsu
author peytoia
date Thu, 25 Jun 2009 21:55:39 +0900
parents 4d54d6e7bcef
children ae9e74a17059
files src/share/classes/sun/text/normalizer/NormalizerBase.java
diffstat 1 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/text/normalizer/NormalizerBase.java	Thu Jun 25 02:42:26 2009 -0700
+++ b/src/share/classes/sun/text/normalizer/NormalizerBase.java	Thu Jun 25 21:55:39 2009 +0900
@@ -1598,15 +1598,34 @@
      * @param options   the optional features to be enabled.
      */
     public static String normalize(String str, Normalizer.Form form, int options) {
+        int len = str.length();
+        boolean asciiOnly = true;
+        if (len < 80) {
+            for (int i = 0; i < len; i++) {
+                if (str.charAt(i) > 127) {
+                    asciiOnly = false;
+                    break;
+                }
+            }
+        } else {
+            char[] a = str.toCharArray();
+            for (int i = 0; i < len; i++) {
+                if (a[i] > 127) {
+                    asciiOnly = false;
+                    break;
+                }
+            }
+        }
+
         switch (form) {
         case NFC :
-            return NFC.normalize(str, options);
+            return asciiOnly ? str : NFC.normalize(str, options);
         case NFD :
-            return NFD.normalize(str, options);
+            return asciiOnly ? str : NFD.normalize(str, options);
         case NFKC :
-            return NFKC.normalize(str, options);
+            return asciiOnly ? str : NFKC.normalize(str, options);
         case NFKD :
-            return NFKD.normalize(str, options);
+            return asciiOnly ? str : NFKD.normalize(str, options);
         }
 
         throw new IllegalArgumentException("Unexpected normalization form: " +