+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
* Copyright (C) 2012-2014, International Business Machines
namespace {
-static const CollationTailoring *rootSingleton = NULL;
+static const CollationCacheEntry *rootSingleton = NULL;
static UInitOnce initOnce = U_INITONCE_INITIALIZER;
} // namespace
U_CDECL_END
-void
+void U_CALLCONV
CollationRoot::load(UErrorCode &errorCode) {
if(U_FAILURE(errorCode)) { return; }
LocalPointer<CollationTailoring> t(new CollationTailoring(NULL));
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 *