< prev index next >

src/java.base/share/classes/sun/util/locale/provider/JRELocaleProviderAdapter.java

Print this page
rev 59021 : 8244152: Remove unnecessary hash map resize in LocaleProviderAdapters
Reviewed-by: joehw, vtewari
   1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 427         return AvailableJRELocales.localeList.clone();
 428     }
 429 
 430     public Set<String> getLanguageTagSet(String category) {
 431         Set<String> tagset = langtagSets.get(category);
 432         if (tagset == null) {
 433             tagset = createLanguageTagSet(category);
 434             Set<String> ts = langtagSets.putIfAbsent(category, tagset);
 435             if (ts != null) {
 436                 tagset = ts;
 437             }
 438         }
 439         return tagset;
 440     }
 441 
 442     protected Set<String> createLanguageTagSet(String category) {
 443         String supportedLocaleString = createSupportedLocaleString(category);
 444         if (supportedLocaleString == null) {
 445             return Collections.emptySet();
 446         }
 447         Set<String> tagset = new HashSet<>();
 448         StringTokenizer tokens = new StringTokenizer(supportedLocaleString);

 449         while (tokens.hasMoreTokens()) {
 450             tagset.add(tokens.nextToken());
 451         }
 452 
 453         return tagset;
 454     }
 455 
 456     private static String createSupportedLocaleString(String category) {
 457         // Directly call Base tags, as we know it's in the base module.
 458         String supportedLocaleString = BaseLocaleDataMetaInfo.getSupportedLocaleString(category);
 459 
 460         // Use ServiceLoader to dynamically acquire installed locales' tags.
 461         try {
 462             String nonBaseTags = AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> {
 463                 StringBuilder tags = new StringBuilder();
 464                 for (LocaleDataMetaInfo ldmi :
 465                         ServiceLoader.loadInstalled(LocaleDataMetaInfo.class)) {
 466                     if (ldmi.getType() == LocaleProviderAdapter.Type.JRE) {
 467                         String t = ldmi.availableLanguageTags(category);
 468                         if (t != null) {


   1 /*
   2  * Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 427         return AvailableJRELocales.localeList.clone();
 428     }
 429 
 430     public Set<String> getLanguageTagSet(String category) {
 431         Set<String> tagset = langtagSets.get(category);
 432         if (tagset == null) {
 433             tagset = createLanguageTagSet(category);
 434             Set<String> ts = langtagSets.putIfAbsent(category, tagset);
 435             if (ts != null) {
 436                 tagset = ts;
 437             }
 438         }
 439         return tagset;
 440     }
 441 
 442     protected Set<String> createLanguageTagSet(String category) {
 443         String supportedLocaleString = createSupportedLocaleString(category);
 444         if (supportedLocaleString == null) {
 445             return Collections.emptySet();
 446         }

 447         StringTokenizer tokens = new StringTokenizer(supportedLocaleString);
 448         Set<String> tagset = new HashSet<>(Math.max((int)(tokens.countTokens() / 0.75f) + 1, 16));
 449         while (tokens.hasMoreTokens()) {
 450             tagset.add(tokens.nextToken());
 451         }
 452 
 453         return tagset;
 454     }
 455 
 456     private static String createSupportedLocaleString(String category) {
 457         // Directly call Base tags, as we know it's in the base module.
 458         String supportedLocaleString = BaseLocaleDataMetaInfo.getSupportedLocaleString(category);
 459 
 460         // Use ServiceLoader to dynamically acquire installed locales' tags.
 461         try {
 462             String nonBaseTags = AccessController.doPrivileged((PrivilegedExceptionAction<String>) () -> {
 463                 StringBuilder tags = new StringBuilder();
 464                 for (LocaleDataMetaInfo ldmi :
 465                         ServiceLoader.loadInstalled(LocaleDataMetaInfo.class)) {
 466                     if (ldmi.getType() == LocaleProviderAdapter.Type.JRE) {
 467                         String t = ldmi.availableLanguageTags(category);
 468                         if (t != null) {


< prev index next >