]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/i18n/collationroot.cpp
ICU-59173.0.1.tar.gz
[apple/icu.git] / icuSources / i18n / collationroot.cpp
index b5d8b49bcf316eabe95af911b803be8e440e8278..71753bd6f4bf20ab4c40d247bef20d0c0d98030d 100644 (file)
@@ -1,3 +1,5 @@
+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
 /*
 *******************************************************************************
 * Copyright (C) 2012-2014, International Business Machines
@@ -30,7 +32,7 @@ U_NAMESPACE_BEGIN
 
 namespace {
 
-static const CollationTailoring *rootSingleton = NULL;
+static const CollationCacheEntry *rootSingleton = NULL;
 static UInitOnce initOnce = U_INITONCE_INITIALIZER;
 
 }  // namespace
@@ -45,7 +47,7 @@ static UBool U_CALLCONV uprv_collation_root_cleanup() {
 
 U_CDECL_END
 
-void
+void U_CALLCONV
 CollationRoot::load(UErrorCode &errorCode) {
     if(U_FAILURE(errorCode)) { return; }
     LocalPointer<CollationTailoring> t(new CollationTailoring(NULL));
@@ -61,15 +63,26 @@ CollationRoot::load(UErrorCode &errorCode) {
     CollationDataReader::read(NULL, inBytes, udata_getLength(t->memory), *t, errorCode);
     if(U_FAILURE(errorCode)) { return; }
     ucln_i18n_registerCleanup(UCLN_I18N_COLLATION_ROOT, uprv_collation_root_cleanup);
-    t->addRef();  // The rootSingleton takes ownership.
-    rootSingleton = t.orphan();
+    CollationCacheEntry *entry = new CollationCacheEntry(Locale::getRoot(), t.getAlias());
+    if(entry != NULL) {
+        t.orphan();  // The rootSingleton took ownership of the tailoring.
+        entry->addRef();
+        rootSingleton = entry;
+    }
+}
+
+const CollationCacheEntry *
+CollationRoot::getRootCacheEntry(UErrorCode &errorCode) {
+    umtx_initOnce(initOnce, CollationRoot::load, errorCode);
+    if(U_FAILURE(errorCode)) { return NULL; }
+    return rootSingleton;
 }
 
 const CollationTailoring *
 CollationRoot::getRoot(UErrorCode &errorCode) {
     umtx_initOnce(initOnce, CollationRoot::load, errorCode);
     if(U_FAILURE(errorCode)) { return NULL; }
-    return rootSingleton;
+    return rootSingleton->tailoring;
 }
 
 const CollationData *