chart2/source/tools/ObjectIdentifier.cxx |   21 ++++++++-------------
 sc/source/core/data/queryevaluator.cxx   |   19 ++++++-------------
 2 files changed, 14 insertions(+), 26 deletions(-)

New commits:
commit 716a81042558143b400c502d1ba3e1ff1b3672e1
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Sep 19 16:05:56 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Sep 19 18:44:53 2022 +0200

    no need to use an OUStringBuffer here
    
    can just return the substring we need
    
    Change-Id: I9d605cb809f58fcf60c0ae2e29aaff17baa9faa0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140177
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/chart2/source/tools/ObjectIdentifier.cxx 
b/chart2/source/tools/ObjectIdentifier.cxx
index ad98d645170f..0952effbbf86 100644
--- a/chart2/source/tools/ObjectIdentifier.cxx
+++ b/chart2/source/tools/ObjectIdentifier.cxx
@@ -155,20 +155,15 @@ rtl::Reference<ChartType> lcl_getFirstStockChartType( 
const rtl::Reference<::cha
 
 OUString lcl_getIndexStringAfterString( const OUString& rString, const 
OUString& rSearchString )
 {
-    OUStringBuffer aRet;
-
     sal_Int32 nIndexStart = rString.lastIndexOf( rSearchString );
-    if( nIndexStart != -1 )
-    {
-        nIndexStart += rSearchString.getLength();
-        sal_Int32 nIndexEnd = rString.getLength();
-        sal_Int32 nNextColon = rString.indexOf( ':', nIndexStart );
-        if( nNextColon != -1 )
-            nIndexEnd = nNextColon;
-        aRet = rString.subView(nIndexStart,nIndexEnd-nIndexStart);
-    }
-
-    return aRet.makeStringAndClear();
+    if( nIndexStart == -1 )
+        return OUString();
+    nIndexStart += rSearchString.getLength();
+    sal_Int32 nIndexEnd = rString.getLength();
+    sal_Int32 nNextColon = rString.indexOf( ':', nIndexStart );
+    if( nNextColon != -1 )
+        nIndexEnd = nNextColon;
+    return rString.copy(nIndexStart,nIndexEnd-nIndexStart);
 }
 
 sal_Int32 lcl_StringToIndex( std::u16string_view rIndexString )
commit c3ea4a8025f1ba241a8ac5c53ac79fd274ec6b3a
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Sep 19 10:58:41 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Sep 19 18:44:42 2022 +0200

    use optional in processEntry
    
    which means we save the cost of initialising an OUString
    
    Change-Id: Ib139383b43f6d49303e20368ce4177b068c38ed9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140176
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/core/data/queryevaluator.cxx 
b/sc/source/core/data/queryevaluator.cxx
index b5ff8a354c84..2562e513c670 100644
--- a/sc/source/core/data/queryevaluator.cxx
+++ b/sc/source/core/data/queryevaluator.cxx
@@ -766,19 +766,15 @@ std::pair<bool, bool> 
ScQueryEvaluator::processEntry(SCROW nRow, SCCOL nCol, ScR
         }
     }
     const svl::SharedString* cellSharedString = nullptr;
-    OUString cellString;
-    bool cellStringSet = false;
+    std::optional<OUString> oCellString;
     const bool bFastCompareByString = isFastCompareByString(rEntry);
     if (rEntry.eOp == SC_EQUAL && rItems.size() >= 10 && bFastCompareByString)
     {
         // The same as above but for strings. Try to optimize the case when
         // it's a svl::SharedString comparison. That happens when SC_EQUAL is 
used
         // and simple matching is used, see compareByString()
-        if (!cellStringSet)
-        {
-            cellString = getCellString(aCell, nRow, rEntry.nField, 
&cellSharedString);
-            cellStringSet = true;
-        }
+        if (!oCellString)
+            oCellString = getCellString(aCell, nRow, rEntry.nField, 
&cellSharedString);
         // Allow also checking ScQueryEntry::ByValue if the cell is not 
numeric,
         // as in that case isQueryByNumeric() would be false and 
isQueryByString() would
         // be true because of SC_EQUAL making isTextMatchOp() true.
@@ -858,18 +854,15 @@ std::pair<bool, bool> 
ScQueryEvaluator::processEntry(SCROW nRow, SCCOL nCol, ScR
         }
         else if (isQueryByString(rEntry.eOp, rItem.meType, aCell))
         {
-            if (!cellStringSet)
-            {
-                cellString = getCellString(aCell, nRow, rEntry.nField, 
&cellSharedString);
-                cellStringSet = true;
-            }
+            if (!oCellString)
+                oCellString = getCellString(aCell, nRow, rEntry.nField, 
&cellSharedString);
             std::pair<bool, bool> aThisRes;
             if (cellSharedString && bFastCompareByString) // fast
                 aThisRes = compareByString<true>(rEntry, rItem, 
cellSharedString, nullptr);
             else if (cellSharedString)
                 aThisRes = compareByString(rEntry, rItem, cellSharedString, 
nullptr);
             else
-                aThisRes = compareByString(rEntry, rItem, nullptr, 
&cellString);
+                aThisRes = compareByString(rEntry, rItem, nullptr, 
&*oCellString);
             aRes.first |= aThisRes.first;
             aRes.second |= aThisRes.second;
         }

Reply via email to