Loading core/java/android/text/Hyphenator.java +13 −11 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,8 @@ public class Hyphenator { @GuardedBy("sLock") @GuardedBy("sLock") final static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>(); final static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>(); final static Hyphenator sEmptyHyphenator = new Hyphenator(StaticLayout.nLoadHyphenator("")); final private long mNativePtr; final private long mNativePtr; private Hyphenator(long nativePtr) { private Hyphenator(long nativePtr) { Loading @@ -53,19 +55,19 @@ public class Hyphenator { public static long get(@Nullable Locale locale) { public static long get(@Nullable Locale locale) { synchronized (sLock) { synchronized (sLock) { if (sMap.containsKey(locale)) { Hyphenator result = sMap.get(locale); Hyphenator result = sMap.get(locale); return (result == null) ? 0 : result.mNativePtr; if (result != null) { return result.mNativePtr; } } // TODO: Convert this a proper locale-fallback system // TODO: Convert this a proper locale-fallback system // Fall back to language-only, if available // Fall back to language-only, if available Locale languageOnlyLocale = new Locale(locale.getLanguage()); Locale languageOnlyLocale = new Locale(locale.getLanguage()); if (sMap.containsKey(languageOnlyLocale)) { result = sMap.get(languageOnlyLocale); Hyphenator result = sMap.get(languageOnlyLocale); if (result != null) { sMap.put(locale, result); sMap.put(locale, result); return (result == null) ? 0 : result.mNativePtr; return result.mNativePtr; } } // Fall back to script-only, if available // Fall back to script-only, if available Loading @@ -75,16 +77,16 @@ public class Hyphenator { .setLanguage("und") .setLanguage("und") .setScript(script) .setScript(script) .build(); .build(); if (sMap.containsKey(scriptOnlyLocale)) { result = sMap.get(scriptOnlyLocale); Hyphenator result = sMap.get(scriptOnlyLocale); if (result != null) { sMap.put(locale, result); sMap.put(locale, result); return (result == null) ? 0 : result.mNativePtr; return result.mNativePtr; } } } } sMap.put(locale, null); // To remember we found nothing. sMap.put(locale, sEmptyHyphenator); // To remember we found nothing. } } return 0; return sEmptyHyphenator.mNativePtr; } } private static Hyphenator loadHyphenator(String languageTag) { private static Hyphenator loadHyphenator(String languageTag) { Loading Loading
core/java/android/text/Hyphenator.java +13 −11 Original line number Original line Diff line number Diff line Loading @@ -45,6 +45,8 @@ public class Hyphenator { @GuardedBy("sLock") @GuardedBy("sLock") final static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>(); final static HashMap<Locale, Hyphenator> sMap = new HashMap<Locale, Hyphenator>(); final static Hyphenator sEmptyHyphenator = new Hyphenator(StaticLayout.nLoadHyphenator("")); final private long mNativePtr; final private long mNativePtr; private Hyphenator(long nativePtr) { private Hyphenator(long nativePtr) { Loading @@ -53,19 +55,19 @@ public class Hyphenator { public static long get(@Nullable Locale locale) { public static long get(@Nullable Locale locale) { synchronized (sLock) { synchronized (sLock) { if (sMap.containsKey(locale)) { Hyphenator result = sMap.get(locale); Hyphenator result = sMap.get(locale); return (result == null) ? 0 : result.mNativePtr; if (result != null) { return result.mNativePtr; } } // TODO: Convert this a proper locale-fallback system // TODO: Convert this a proper locale-fallback system // Fall back to language-only, if available // Fall back to language-only, if available Locale languageOnlyLocale = new Locale(locale.getLanguage()); Locale languageOnlyLocale = new Locale(locale.getLanguage()); if (sMap.containsKey(languageOnlyLocale)) { result = sMap.get(languageOnlyLocale); Hyphenator result = sMap.get(languageOnlyLocale); if (result != null) { sMap.put(locale, result); sMap.put(locale, result); return (result == null) ? 0 : result.mNativePtr; return result.mNativePtr; } } // Fall back to script-only, if available // Fall back to script-only, if available Loading @@ -75,16 +77,16 @@ public class Hyphenator { .setLanguage("und") .setLanguage("und") .setScript(script) .setScript(script) .build(); .build(); if (sMap.containsKey(scriptOnlyLocale)) { result = sMap.get(scriptOnlyLocale); Hyphenator result = sMap.get(scriptOnlyLocale); if (result != null) { sMap.put(locale, result); sMap.put(locale, result); return (result == null) ? 0 : result.mNativePtr; return result.mNativePtr; } } } } sMap.put(locale, null); // To remember we found nothing. sMap.put(locale, sEmptyHyphenator); // To remember we found nothing. } } return 0; return sEmptyHyphenator.mNativePtr; } } private static Hyphenator loadHyphenator(String languageTag) { private static Hyphenator loadHyphenator(String languageTag) { Loading