From bbd33e6ddc179efbe5db3ffe4f18e88a7934ff07 Mon Sep 17 00:00:00 2001 From: Yuka Kamiya Date: Thu, 25 Jun 2009 21:55:39 +0900 Subject: [PATCH] 6792400: Avoid loading of Normalizer resources for simple uses Reviewed-by: okutsu --- .../sun/text/normalizer/NormalizerBase.java | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/jdk/src/share/classes/sun/text/normalizer/NormalizerBase.java b/jdk/src/share/classes/sun/text/normalizer/NormalizerBase.java index a82475c6009..b4df3e2a659 100644 --- a/jdk/src/share/classes/sun/text/normalizer/NormalizerBase.java +++ b/jdk/src/share/classes/sun/text/normalizer/NormalizerBase.java @@ -1598,15 +1598,34 @@ public final class NormalizerBase implements Cloneable { * @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: " +