[Libreoffice-commits] core.git: i18npool/inc i18npool/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Wed Aug 11 08:54:56 UTC 2021


 i18npool/inc/characterclassificationImpl.hxx                            |    5 +--
 i18npool/inc/collatorImpl.hxx                                           |    5 +--
 i18npool/inc/inputsequencechecker.hxx                                   |    5 +--
 i18npool/source/characterclassification/characterclassificationImpl.cxx |   16 +++++-----
 i18npool/source/collator/collatorImpl.cxx                               |   15 ++++-----
 i18npool/source/inputchecker/inputsequencechecker.cxx                   |    8 +----
 6 files changed, 27 insertions(+), 27 deletions(-)

New commits:
commit 5ef182586ae2019fa6f6a59dae1b41b2225665bf
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Tue Aug 10 20:53:07 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Wed Aug 11 10:54:22 2021 +0200

    no need to allocate the lookupTableItem separately
    
    Change-Id: I43919a002df01c6329ee483bf69f04669cdce1f6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120293
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/i18npool/inc/characterclassificationImpl.hxx b/i18npool/inc/characterclassificationImpl.hxx
index 34723ef74123..4e03a54fd3be 100644
--- a/i18npool/inc/characterclassificationImpl.hxx
+++ b/i18npool/inc/characterclassificationImpl.hxx
@@ -23,6 +23,7 @@
 #include <cppuhelper/implbase.hxx>
 #include <vector>
 #include <memory>
+#include <optional>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 
 namespace com::sun::star::uno { class XComponentContext; }
@@ -81,8 +82,8 @@ private:
             aLocale.Variant == rLocale.Variant;
         };
     };
-    std::vector<std::unique_ptr<lookupTableItem>> lookupTable;
-    lookupTableItem *cachedItem;
+    std::vector<lookupTableItem> lookupTable;
+    std::optional<lookupTableItem> cachedItem;
 
     css::uno::Reference < css::uno::XComponentContext > m_xContext;
     css::uno::Reference < XCharacterClassification > xUCI;
diff --git a/i18npool/inc/collatorImpl.hxx b/i18npool/inc/collatorImpl.hxx
index 14a4489a256a..c1068638d8bc 100644
--- a/i18npool/inc/collatorImpl.hxx
+++ b/i18npool/inc/collatorImpl.hxx
@@ -27,6 +27,7 @@
 
 #include <vector>
 #include <memory>
+#include <optional>
 
 namespace com::sun::star::i18n { class XLocaleData5; }
 namespace com::sun::star::uno { class XComponentContext; }
@@ -89,8 +90,8 @@ private:
             algorithm == _algorithm;
         }
     };
-    std::vector<std::unique_ptr<lookupTableItem>>       lookupTable;
-    lookupTableItem *                                   cachedItem;
+    std::vector<lookupTableItem>       lookupTable;
+    std::optional<lookupTableItem>     cachedItem;
 
     // Service Factory
     css::uno::Reference < css::uno::XComponentContext > m_xContext;
diff --git a/i18npool/inc/inputsequencechecker.hxx b/i18npool/inc/inputsequencechecker.hxx
index 52963b3be171..eff426f5caa3 100644
--- a/i18npool/inc/inputsequencechecker.hxx
+++ b/i18npool/inc/inputsequencechecker.hxx
@@ -25,6 +25,7 @@
 
 #include <vector>
 #include <memory>
+#include <optional>
 
 namespace com::sun::star::uno { class XComponentContext; }
 
@@ -63,8 +64,8 @@ private:
         const char* aLanguage;
         css::uno::Reference < css::i18n::XExtendedInputSequenceChecker > xISC;
     };
-    std::vector<std::unique_ptr<lookupTableItem>> lookupTable;
-    lookupTableItem *cachedItem;
+    std::vector<lookupTableItem> lookupTable;
+    std::optional<lookupTableItem> cachedItem;
 
     css::uno::Reference < css::uno::XComponentContext > m_xContext;
 
diff --git a/i18npool/source/characterclassification/characterclassificationImpl.cxx b/i18npool/source/characterclassification/characterclassificationImpl.cxx
index 721c82bf9304..8146612a87fc 100644
--- a/i18npool/source/characterclassification/characterclassificationImpl.cxx
+++ b/i18npool/source/characterclassification/characterclassificationImpl.cxx
@@ -125,10 +125,10 @@ bool CharacterClassificationImpl::createLocaleSpecificCharacterClassification(co
 {
     // to share service between same Language but different Country code, like zh_CN and zh_SG
     for (size_t l = 0; l < lookupTable.size(); l++) {
-        cachedItem = lookupTable[l].get();
+        cachedItem = lookupTable[l];
         if (serviceName == cachedItem->aName) {
-            lookupTable.emplace_back( new lookupTableItem(rLocale, serviceName, cachedItem->xCI) );
-            cachedItem = lookupTable.back().get();
+            lookupTable.emplace_back( rLocale, serviceName, cachedItem->xCI );
+            cachedItem = lookupTable.back();
             return true;
         }
     }
@@ -140,8 +140,8 @@ bool CharacterClassificationImpl::createLocaleSpecificCharacterClassification(co
     if ( xI.is() ) {
         xCI.set( xI, UNO_QUERY );
         if (xCI.is()) {
-            lookupTable.emplace_back( new lookupTableItem(rLocale, serviceName, xCI) );
-            cachedItem = lookupTable.back().get();
+            lookupTable.emplace_back( rLocale, serviceName, xCI );
+            cachedItem = lookupTable.back();
             return true;
         }
     }
@@ -156,7 +156,7 @@ CharacterClassificationImpl::getLocaleSpecificCharacterClassification(const Loca
         return cachedItem->xCI;
     else {
         for (const auto & i : lookupTable) {
-            cachedItem = i.get();
+            cachedItem = i;
             if (cachedItem->equals(rLocale))
                 return cachedItem->xCI;
         }
@@ -179,8 +179,8 @@ CharacterClassificationImpl::getLocaleSpecificCharacterClassification(const Loca
             return cachedItem->xCI;
         else if (xUCI.is())
         {
-            lookupTable.emplace_back( new lookupTableItem(rLocale, "Unicode", xUCI) );
-            cachedItem = lookupTable.back().get();
+            lookupTable.emplace_back( rLocale, "Unicode", xUCI );
+            cachedItem = lookupTable.back();
             return cachedItem->xCI;
         }
     }
diff --git a/i18npool/source/collator/collatorImpl.cxx b/i18npool/source/collator/collatorImpl.cxx
index 3253b458159f..56fb4bf90502 100644
--- a/i18npool/source/collator/collatorImpl.cxx
+++ b/i18npool/source/collator/collatorImpl.cxx
@@ -34,7 +34,6 @@ namespace i18npool {
 CollatorImpl::CollatorImpl( const Reference < XComponentContext >& rxContext ) : m_xContext(rxContext)
 {
     mxLocaleData.set( LocaleData2::create(rxContext) );
-    cachedItem = nullptr;
 }
 
 CollatorImpl::~CollatorImpl()
@@ -139,10 +138,10 @@ bool
 CollatorImpl::createCollator(const lang::Locale& rLocale, const OUString& serviceName, const OUString& rSortAlgorithm)
 {
     for (size_t l = 0; l < lookupTable.size(); l++) {
-        cachedItem = lookupTable[l].get();
+        cachedItem = lookupTable[l];
         if (cachedItem->service == serviceName) {// cross locale sharing
-            lookupTable.emplace_back(new lookupTableItem(rLocale, rSortAlgorithm, serviceName, cachedItem->xC));
-            cachedItem = lookupTable.back().get();
+            lookupTable.emplace_back(rLocale, rSortAlgorithm, serviceName, cachedItem->xC);
+            cachedItem = lookupTable.back();
             return true;
         }
     }
@@ -153,8 +152,8 @@ CollatorImpl::createCollator(const lang::Locale& rLocale, const OUString& servic
         Reference < XCollator > xC;
         xC.set( xI, UNO_QUERY );
         if (xC.is()) {
-            lookupTable.emplace_back(new lookupTableItem(rLocale, rSortAlgorithm, serviceName, xC));
-            cachedItem = lookupTable.back().get();
+            lookupTable.emplace_back(rLocale, rSortAlgorithm, serviceName, xC);
+            cachedItem = lookupTable.back();
             return true;
         }
     }
@@ -165,7 +164,7 @@ void
 CollatorImpl::loadCachedCollator(const lang::Locale& rLocale, const OUString& rSortAlgorithm)
 {
     for (const auto& i : lookupTable) {
-        cachedItem = i.get();
+        cachedItem = i;
         if (cachedItem->equals(rLocale, rSortAlgorithm)) {
             return;
         }
@@ -200,7 +199,7 @@ CollatorImpl::loadCachedCollator(const lang::Locale& rLocale, const OUString& rS
         bLoaded = createCollator( rLocale, "Unicode", rSortAlgorithm);
         if (!bLoaded)
         {
-            cachedItem = nullptr;
+            cachedItem.reset();
             throw RuntimeException();   // could not load any service
         }
     }
diff --git a/i18npool/source/inputchecker/inputsequencechecker.cxx b/i18npool/source/inputchecker/inputsequencechecker.cxx
index f27ed5c9e266..4820c10ca153 100644
--- a/i18npool/source/inputchecker/inputsequencechecker.cxx
+++ b/i18npool/source/inputchecker/inputsequencechecker.cxx
@@ -32,12 +32,10 @@ namespace i18npool {
 InputSequenceCheckerImpl::InputSequenceCheckerImpl( const Reference < XComponentContext >& rxContext ) : m_xContext( rxContext )
 {
     serviceName = "com.sun.star.i18n.InputSequenceChecker";
-    cachedItem = nullptr;
 }
 
 InputSequenceCheckerImpl::InputSequenceCheckerImpl(const char *pServiceName)
     : serviceName(pServiceName)
-    , cachedItem(nullptr)
 {
 }
 
@@ -109,7 +107,7 @@ InputSequenceCheckerImpl::getInputSequenceChecker(char const * rLanguage)
     }
     else {
         for (const auto& l : lookupTable) {
-            cachedItem = l.get();
+            cachedItem = l;
             if (cachedItem->aLanguage == rLanguage)
                 return cachedItem->xISC;
         }
@@ -122,8 +120,8 @@ InputSequenceCheckerImpl::getInputSequenceChecker(char const * rLanguage)
         if ( xI.is() ) {
             Reference< XExtendedInputSequenceChecker > xISC( xI, UNO_QUERY );
             if (xISC.is()) {
-                lookupTable.emplace_back(new lookupTableItem(rLanguage, xISC));
-                cachedItem = lookupTable.back().get();
+                lookupTable.emplace_back(rLanguage, xISC);
+                cachedItem = lookupTable.back();
                 return cachedItem->xISC;
             }
         }


More information about the Libreoffice-commits mailing list