[Libreoffice-commits] core.git: chart2/source dbaccess/source sc/source sfx2/source vcl/win

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Fri May 15 06:48:40 UTC 2020


 chart2/source/tools/AxisHelper.cxx          |    5 +----
 chart2/source/view/charttypes/AreaChart.cxx |    3 +--
 chart2/source/view/charttypes/NetChart.cxx  |    3 +--
 dbaccess/source/core/api/OptimisticSet.cxx  |    6 ++----
 sc/source/filter/oox/stylesbuffer.cxx       |    3 +--
 sc/source/ui/unoobj/chart2uno.cxx           |    6 ++----
 sfx2/source/view/classificationhelper.cxx   |    6 ++----
 vcl/win/app/salinfo.cxx                     |    5 +----
 8 files changed, 11 insertions(+), 26 deletions(-)

New commits:
commit 4f6931d68664237f7f7eb1f55988b713034c77ba
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Wed May 13 18:51:35 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri May 15 08:48:06 2020 +0200

    use more try_emplace
    
    specifically looking for the pattern
       if (map.find(...) == map.end()
         map[...] = value
    
    Change-Id: I99f20d73f6e71a10726c9d39d8644c2e51120091
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94151
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/chart2/source/tools/AxisHelper.cxx b/chart2/source/tools/AxisHelper.cxx
index c836d7646114..2f9a14c0442f 100644
--- a/chart2/source/tools/AxisHelper.cxx
+++ b/chart2/source/tools/AxisHelper.cxx
@@ -278,11 +278,8 @@ sal_Int32 AxisHelper::getExplicitNumberFormatKeyForAxis(
                             if( xSeq.is() )
                             {
                                 sal_Int32 nKey = xSeq->getNumberFormatKeyByIndex( -1 );
-                                // initialize the value
-                                if( aKeyMap.find( nKey ) == aKeyMap.end())
-                                    aKeyMap[ nKey ] = 0;
                                 // increase frequency
-                                aKeyMap[ nKey ] = (aKeyMap[ nKey ] + 1);
+                                aKeyMap[ nKey ] ++;
                             }
                         }
                     }
diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx
index 0d7e88936d8f..a658a26d04a6 100644
--- a/chart2/source/view/charttypes/AreaChart.cxx
+++ b/chart2/source/view/charttypes/AreaChart.cxx
@@ -749,8 +749,7 @@ void AreaChart::createShapes()
                     }
 
                     std::map< sal_Int32, double >& rLogicYForNextSeriesMap = aLogicYForNextSeriesMapByX[nIndex];
-                    if( rLogicYForNextSeriesMap.find(nAttachedAxisIndex) == rLogicYForNextSeriesMap.end() )
-                        rLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0;
+                    rLogicYForNextSeriesMap.try_emplace(nAttachedAxisIndex, 0.0);
 
                     double fPreviousYValue = rLogicYForNextSeriesMap[nAttachedAxisIndex];
                     fLogicY += rLogicYForNextSeriesMap[nAttachedAxisIndex];
diff --git a/chart2/source/view/charttypes/NetChart.cxx b/chart2/source/view/charttypes/NetChart.cxx
index 2205351dfd0d..a8a0f776dd24 100644
--- a/chart2/source/view/charttypes/NetChart.cxx
+++ b/chart2/source/view/charttypes/NetChart.cxx
@@ -450,8 +450,7 @@ void NetChart::createShapes()
                         continue;
                     }
 
-                    if( aLogicYForNextSeriesMap.find(nAttachedAxisIndex) == aLogicYForNextSeriesMap.end() )
-                        aLogicYForNextSeriesMap[nAttachedAxisIndex] = 0.0;
+                    aLogicYForNextSeriesMap.try_emplace(nAttachedAxisIndex, 0.0);
 
                     double fLogicValueForLabeDisplay = fLogicY;
 
diff --git a/dbaccess/source/core/api/OptimisticSet.cxx b/dbaccess/source/core/api/OptimisticSet.cxx
index 734e58edf34e..67fd18aaaea7 100644
--- a/dbaccess/source/core/api/OptimisticSet.cxx
+++ b/dbaccess/source/core/api/OptimisticSet.cxx
@@ -168,8 +168,7 @@ void OptimisticSet::updateRow(const ORowSetRow& _rInsertRow ,const ORowSetRow& _
     // here we build the condition part for the update statement
     for (auto const& columnName : *m_pColumnNames)
     {
-        if ( aResultSetChanged.find( columnName.second.sTableName ) == aResultSetChanged.end() )
-            aResultSetChanged[columnName.second.sTableName] = false;
+        aResultSetChanged.try_emplace(columnName.second.sTableName, false);
         const OUString sQuotedColumnName = ::dbtools::quoteName( aQuote,columnName.second.sRealName);
         if ( m_pKeyColumnNames->find(columnName.first) != m_pKeyColumnNames->end() )
         {
@@ -230,8 +229,7 @@ void OptimisticSet::insertRow( const ORowSetRow& _rInsertRow,const connectivity:
     // here we build the condition part for the update statement
     for (auto const& columnName : *m_pColumnNames)
     {
-        if ( aResultSetChanged.find( columnName.second.sTableName ) == aResultSetChanged.end() )
-            aResultSetChanged[columnName.second.sTableName] = false;
+        aResultSetChanged.try_emplace(columnName.second.sTableName, false);
 
         const OUString sQuotedColumnName = ::dbtools::quoteName( aQuote,columnName.second.sRealName);
         if ( (*_rInsertRow)[columnName.second.nPosition].isModified() )
diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx
index de613565fd0f..0895f87a2f98 100644
--- a/sc/source/filter/oox/stylesbuffer.cxx
+++ b/sc/source/filter/oox/stylesbuffer.cxx
@@ -2614,8 +2614,7 @@ void CellStyleBuffer::finalizeImport()
         {
             aUnusedName = aStyleName + OUStringChar(' ') + OUString::number( ++nIndex );
         }
-        while( aCellStyles.find( aUnusedName ) != aCellStyles.end() );
-        aCellStyles[ aUnusedName ] = rxStyle;
+        while( !aCellStyles.try_emplace( aUnusedName, rxStyle ).second );
     }
 
     // set final names and create user-defined and modified built-in cell styles
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index 1c5854479125..cdb8303adc7c 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -781,8 +781,7 @@ void Chart2Positioner::createPositionMap()
     {
         FormulaTokenMap& rCol = aCols.begin()->second;
         if (mbDummyUpperLeft)
-            if (rCol.find(0) == rCol.end())
-                rCol[ 0 ] = nullptr;        // dummy for labeling
+            rCol.try_emplace( 0, nullptr );        // dummy for labeling
         nAllRowCount = static_cast<SCSIZE>(rCol.size());
     }
 
@@ -797,8 +796,7 @@ void Chart2Positioner::createPositionMap()
                 for (auto& rEntry : aCols)
                 {
                     FormulaTokenMap& rCol = rEntry.second;
-                    if (rCol.find(nKey) == rCol.end())
-                        rCol[ nKey ] = nullptr;
+                    rCol.try_emplace( nKey, nullptr );
                 }
             }
         }
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 1309bc774418..097cc20b4bdb 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -291,10 +291,8 @@ void SAL_CALL SfxClassificationParser::endElement(const OUString& rName)
             m_pCategory->m_nConfidentiality = m_aConfidentalityValue.toInt32(); // 0-based class sensitivity; 0 is lowest.
             // Set the two other type of levels as well, if they're not set
             // yet: they're optional in BAF, but not in BAILS.
-            if (rLabels.find("Impact:Level:Integrity") == rLabels.end())
-                rLabels["Impact:Level:Integrity"] = m_aConfidentalityValue;
-            if (rLabels.find("Impact:Level:Availability") == rLabels.end())
-                rLabels["Impact:Level:Availability"] = m_aConfidentalityValue;
+            rLabels.try_emplace("Impact:Level:Integrity", m_aConfidentalityValue);
+            rLabels.try_emplace("Impact:Level:Availability", m_aConfidentalityValue);
         }
     }
     else if (rName == "baf:Identifier")
diff --git a/vcl/win/app/salinfo.cxx b/vcl/win/app/salinfo.cxx
index a19ca597f9c5..2787797a6ce5 100644
--- a/vcl/win/app/salinfo.cxx
+++ b/vcl/win/app/salinfo.cxx
@@ -112,10 +112,7 @@ bool WinSalSystem::initMonitors()
                 aDev.DeviceString[127] = 0;
                 OUString aDeviceName( o3tl::toU(aDev.DeviceName) );
                 OUString aDeviceString( o3tl::toU(aDev.DeviceString) );
-                if( aDeviceStringCount.find( aDeviceString ) == aDeviceStringCount.end() )
-                    aDeviceStringCount[ aDeviceString ] = 1;
-                else
-                    aDeviceStringCount[ aDeviceString ]++;
+                aDeviceStringCount[ aDeviceString ]++;
                 m_aDeviceNameToMonitor[ aDeviceName ] = m_aMonitors.size();
                 m_aMonitors.push_back( DisplayMonitor( aDeviceString,
                                                        tools::Rectangle() ) );


More information about the Libreoffice-commits mailing list