[Libreoffice-commits] core.git: configmgr/source

Eike Rathke (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 15 00:58:05 UTC 2021


 configmgr/source/access.cxx |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

New commits:
commit 6c4ff1d23ef61e708f3450d1b0ae77cc78cac731
Author:     Eike Rathke <erack at redhat.com>
AuthorDate: Sun Aug 15 01:44:54 2021 +0200
Commit:     Eike Rathke <erack at redhat.com>
CommitDate: Sun Aug 15 02:57:21 2021 +0200

    Avoid computing LanguageTag fallbacks several hundred times
    
    ... over and over again even for known and present locales for
    each and every localizable config item.
    
    Change-Id: I19974c56169f45a7c53ed6b0eede47365e1365dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120496
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Jenkins

diff --git a/configmgr/source/access.cxx b/configmgr/source/access.cxx
index 02e3f557c684..28ef91000fb1 100644
--- a/configmgr/source/access.cxx
+++ b/configmgr/source/access.cxx
@@ -1385,8 +1385,14 @@ rtl::Reference< ChildAccess > Access::getChild(OUString const & name) {
             locale = comphelper::LibreOfficeKit::getLanguageTag().getBcp47();
 
         if (!locale.isEmpty()) {
-            // Find the best match using the LanguageTag fallback mechanism
-            std::vector<OUString> aFallbacks = LanguageTag(locale).getFallbackStrings(true);
+            // Try exact match first, avoiding all fallback overhead.
+            rtl::Reference<ChildAccess> directChild(getChild(locale));
+            if (directChild.is())
+                return directChild;
+
+            // Find the best match using the LanguageTag fallback mechanism,
+            // excluding the original tag.
+            std::vector<OUString> aFallbacks = LanguageTag(locale).getFallbackStrings(false);
             for (const OUString& rFallback : aFallbacks)
             {
                 rtl::Reference<ChildAccess> child(getChild(rFallback));
@@ -1398,8 +1404,8 @@ rtl::Reference< ChildAccess > Access::getChild(OUString const & name) {
             // xml:lang attributes, look for the first entry with the same first
             // segment as the requested language tag before falling back to
             // defaults (see fdo#33638):
-            assert(aFallbacks.size() > 0);
-            locale = aFallbacks[aFallbacks.size() - 1];
+            if (aFallbacks.size() > 0)
+                locale = aFallbacks[aFallbacks.size() - 1];
             assert(
                 !locale.isEmpty() && locale.indexOf('-') == -1 &&
                 locale.indexOf('_') == -1);


More information about the Libreoffice-commits mailing list