toolkit/source/controls/table/cellvalueconversion.cxx |   25 +++++++-----------
 1 file changed, 10 insertions(+), 15 deletions(-)

New commits:
commit e97e2bd61c2a0a4fc75c3726eea280df6a7448b2
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Thu Sep 11 11:45:43 2025 +0200
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Thu Sep 11 19:55:34 2025 +0200

    Use try_emplace to avoid second lookup
    
    Change-Id: I7629e7b5fd8b30fd2f7ffafbafcd18bef44b5f2d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/190810
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/toolkit/source/controls/table/cellvalueconversion.cxx 
b/toolkit/source/controls/table/cellvalueconversion.cxx
index 7a5ad2caa41a..da9a83346565 100644
--- a/toolkit/source/controls/table/cellvalueconversion.cxx
+++ b/toolkit/source/controls/table/cellvalueconversion.cxx
@@ -301,52 +301,47 @@ bool CellValueConversion::ensureNumberFormatter()
 
 const StandardFormatNormalizer* CellValueConversion::getValueNormalizer(Type 
const& i_valueType)
 {
-    auto pos = aNormalizers.find(i_valueType.getTypeName());
-    if (pos == aNormalizers.end())
+    auto [pos, inserted] = aNormalizers.try_emplace(i_valueType.getTypeName());
+    if (inserted)
     {
         // never encountered this type before
-        std::unique_ptr<StandardFormatNormalizer> o_formatter;
-
         OUString const sTypeName(i_valueType.getTypeName());
         TypeClass const eTypeClass = i_valueType.getTypeClass();
 
         if (sTypeName == ::cppu::UnoType<DateTime>::get().getTypeName())
         {
-            o_formatter = 
std::make_unique<DateTimeNormalization>(xNumberFormatter);
+            pos->second = 
std::make_unique<DateTimeNormalization>(xNumberFormatter);
         }
         else if (sTypeName == 
::cppu::UnoType<css::util::Date>::get().getTypeName())
         {
-            o_formatter = 
std::make_unique<DateNormalization>(xNumberFormatter);
+            pos->second = 
std::make_unique<DateNormalization>(xNumberFormatter);
         }
         else if (sTypeName == 
::cppu::UnoType<css::util::Time>::get().getTypeName())
         {
-            o_formatter = 
std::make_unique<TimeNormalization>(xNumberFormatter);
+            pos->second = 
std::make_unique<TimeNormalization>(xNumberFormatter);
         }
         else if (sTypeName == ::cppu::UnoType<sal_Bool>::get().getTypeName())
         {
-            o_formatter = 
std::make_unique<BooleanNormalization>(xNumberFormatter);
+            pos->second = 
std::make_unique<BooleanNormalization>(xNumberFormatter);
         }
         else if (sTypeName == ::cppu::UnoType<double>::get().getTypeName()
                  || sTypeName == ::cppu::UnoType<float>::get().getTypeName())
         {
-            o_formatter = 
std::make_unique<DoubleNormalization>(xNumberFormatter);
+            pos->second = 
std::make_unique<DoubleNormalization>(xNumberFormatter);
         }
         else if ((eTypeClass == TypeClass_BYTE) || (eTypeClass == 
TypeClass_SHORT)
                  || (eTypeClass == TypeClass_UNSIGNED_SHORT) || (eTypeClass == 
TypeClass_LONG)
                  || (eTypeClass == TypeClass_UNSIGNED_LONG) || (eTypeClass == 
TypeClass_HYPER))
         {
-            o_formatter = 
std::make_unique<IntegerNormalization>(xNumberFormatter);
+            pos->second = 
std::make_unique<IntegerNormalization>(xNumberFormatter);
         }
         else
         {
             SAL_WARN("svtools.table", "unsupported type '" << sTypeName << 
"'!");
         }
-        auto& newValue = aNormalizers[sTypeName];
-        newValue = std::move(o_formatter);
-        return newValue.get();
     }
-    else
-        return pos->second.get();
+
+    return pos->second.get();
 }
 
 //= CellValueConversion

Reply via email to