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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Nov 10 13:07:36 UTC 2018


 vcl/inc/svdata.hxx            |    4 ++--
 vcl/source/app/svdata.cxx     |   29 +++++++++++++----------------
 vcl/source/control/field.cxx  |   26 +++++++++-----------------
 vcl/source/window/builder.cxx |   16 +++++++---------
 4 files changed, 31 insertions(+), 44 deletions(-)

New commits:
commit 0408b72ae93d7cce9f64c4779f19d645d694df95
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed Nov 7 09:40:54 2018 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sat Nov 10 14:07:15 2018 +0100

    tdf#120703 PVS: make ImplGet(Cleaned)FieldUnits return reference
    
    V547 Expression 'pUnits' is always true.
    
    Change-Id: I2bd31fcc31c36b43d14ff2a10a7143b9fbe86b3d
    Reviewed-on: https://gerrit.libreoffice.org/63228
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index b36ecf7e6a41..5ae913a0dbca 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -396,8 +396,8 @@ VCL_PLUGIN_PUBLIC void ImplHideSplash();
 bool ImplInitAccessBridge();
 #endif
 
-FieldUnitStringList* ImplGetFieldUnits();
-FieldUnitStringList* ImplGetCleanedFieldUnits();
+const FieldUnitStringList& ImplGetFieldUnits();
+const FieldUnitStringList& ImplGetCleanedFieldUnits();
 
 struct ImplSVEvent
 {
diff --git a/vcl/source/app/svdata.cxx b/vcl/source/app/svdata.cxx
index edbcc3b4e870..529eb676e3ad 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -291,7 +291,7 @@ OUString VclResId(const char* pId)
     return Translate::get(pId, ImplGetResLocale());
 }
 
-FieldUnitStringList* ImplGetFieldUnits()
+const FieldUnitStringList& ImplGetFieldUnits()
 {
     ImplSVData* pSVData = ImplGetSVData();
     if( pSVData->maCtrlData.maFieldUnitStrings.empty() )
@@ -304,30 +304,27 @@ FieldUnitStringList* ImplGetFieldUnits()
             pSVData->maCtrlData.maFieldUnitStrings.push_back( aElement );
         }
     }
-    return &pSVData->maCtrlData.maFieldUnitStrings;
+    return pSVData->maCtrlData.maFieldUnitStrings;
 }
 
-FieldUnitStringList* ImplGetCleanedFieldUnits()
+const FieldUnitStringList& ImplGetCleanedFieldUnits()
 {
     ImplSVData* pSVData = ImplGetSVData();
     if( pSVData->maCtrlData.maCleanUnitStrings.empty() )
     {
-        FieldUnitStringList* pUnits = ImplGetFieldUnits();
-        if( pUnits )
+        const FieldUnitStringList& rUnits = ImplGetFieldUnits();
+        size_t nUnits = rUnits.size();
+        pSVData->maCtrlData.maCleanUnitStrings.reserve(nUnits);
+        for (size_t i = 0; i < nUnits; ++i)
         {
-            size_t nUnits = pUnits->size();
-            pSVData->maCtrlData.maCleanUnitStrings.reserve( nUnits );
-            for( size_t i = 0; i < nUnits; ++i )
-            {
-                OUString aUnit( (*pUnits)[i].first );
-                aUnit = aUnit.replaceAll(" ", "");
-                aUnit = aUnit.toAsciiLowerCase();
-                std::pair< OUString, FieldUnit > aElement( aUnit, (*pUnits)[i].second );
-                pSVData->maCtrlData.maCleanUnitStrings.push_back( aElement );
-            }
+            OUString aUnit(rUnits[i].first);
+            aUnit = aUnit.replaceAll(" ", "");
+            aUnit = aUnit.toAsciiLowerCase();
+            std::pair<OUString, FieldUnit> aElement(aUnit, rUnits[i].second);
+            pSVData->maCtrlData.maCleanUnitStrings.push_back(aElement);
         }
     }
-    return &pSVData->maCtrlData.maCleanUnitStrings;
+    return pSVData->maCtrlData.maCleanUnitStrings;
 }
 
 DockingManager* ImplGetDockingManager()
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index 23c6905548b6..8cf40c6e7682 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -999,15 +999,11 @@ static OUString ImplMetricGetUnitText(const OUString& rStr)
 
 static const OUString ImplMetricToString( FieldUnit rUnit )
 {
-    FieldUnitStringList* pList = ImplGetFieldUnits();
-    if( pList )
+    // return unit's default string (ie, the first one )
+    for (auto const& elem : ImplGetFieldUnits())
     {
-        // return unit's default string (ie, the first one )
-        for (auto const& elem : *pList)
-        {
-            if ( elem.second == rUnit )
-                return elem.first;
-        }
+        if (elem.second == rUnit)
+            return elem.first;
     }
 
     return OUString();
@@ -1015,16 +1011,12 @@ static const OUString ImplMetricToString( FieldUnit rUnit )
 
 FieldUnit MetricFormatter::StringToMetric(const OUString &rMetricString)
 {
-    FieldUnitStringList* pList = ImplGetCleanedFieldUnits();
-    if( pList )
+    // return FieldUnit
+    OUString aStr = rMetricString.toAsciiLowerCase().replaceAll(" ", "");
+    for (auto const& elem : ImplGetCleanedFieldUnits())
     {
-        // return FieldUnit
-        OUString aStr = rMetricString.toAsciiLowerCase().replaceAll(" ", "");
-        for (auto const& elem : *pList)
-        {
-            if ( elem.first == aStr )
-                return elem.second;
-        }
+        if ( elem.first == aStr )
+            return elem.second;
     }
 
     return FieldUnit::NONE;
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index c56ac2242304..fe81a0f36016 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -161,15 +161,13 @@ namespace weld
 {
     OUString MetricSpinButton::MetricToString(FieldUnit rUnit)
     {
-        FieldUnitStringList* pList = ImplGetFieldUnits();
-        if (pList)
-        {
-            // return unit's default string (ie, the first one )
-            auto it = std::find_if(pList->begin(), pList->end(),
-                [&rUnit](std::pair<OUString, FieldUnit>& rItem) { return rItem.second == rUnit; });
-            if (it != pList->end())
-                return it->first;
-        }
+        const FieldUnitStringList& rList = ImplGetFieldUnits();
+        // return unit's default string (ie, the first one )
+        auto it = std::find_if(
+            rList.begin(), rList.end(),
+            [&rUnit](const std::pair<OUString, FieldUnit>& rItem) { return rItem.second == rUnit; });
+        if (it != rList.end())
+            return it->first;
 
         return OUString();
     }


More information about the Libreoffice-commits mailing list