include/rtl/ustrbuf.hxx        |   33 +++++++++++++++++++++++++++++++++
 svl/source/numbers/zformat.cxx |   19 +++++++------------
 2 files changed, 40 insertions(+), 12 deletions(-)

New commits:
commit 2cb2e2b9c1d55bbbc639997ca30fd6b57a81bfb2
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Mon Mar 13 12:11:04 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Mar 13 13:05:41 2023 +0000

    Introduce OUStringBuffer::insert taking OUStringConcat
    
    Avoids some (re)allocations, and aligns with already existing append
    
    Change-Id: I536ba50f56fc560c0f6e8c0a8b65bd4248896a8e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148777
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index af7d0d0d9ef6..cdfb28ab556c 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -43,6 +43,7 @@
 #include "sal/types.h"
 
 #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+#include "o3tl/safeint.hxx"
 #include "rtl/stringconcat.hxx"
 #endif
 
@@ -1015,6 +1016,38 @@ public:
     }
 #endif
 
+#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
+    /**
+     @overload
+     @internal
+    */
+    template <typename T1, typename T2>
+    OUStringBuffer& insert(sal_Int32 offset, OUStringConcat<T1, T2>&& c)
+    {
+        const size_t l = c.length();
+        if (l == 0)
+            return *this;
+        if (l > o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max() - 
pData->length))
+            throw std::bad_alloc();
+
+        rtl_uStringbuffer_insert(&pData, &nCapacity, offset, nullptr, l);
+
+        /* insert the new characters */
+        c.addData(pData->buffer + offset);
+        return *this;
+    }
+
+    /**
+     @overload
+     @internal
+    */
+    template <typename T, std::size_t N>
+    OUStringBuffer& insert(sal_Int32 offset, StringNumberBase<sal_Unicode, T, 
N>&& c)
+    {
+        return insert(offset, c.buf, c.length);
+    }
+#endif
+
     /**
         Inserts the string representation of the <code>char</code> array
         argument into this string buffer.
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index effb34ad996f..549194736e69 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -709,7 +709,7 @@ OUString SvNumberformat::ImpObtainCalendarAndNumerals( 
OUStringBuffer& rString,
     if ( nNumeralID >= 0x02 && nNumeralID <= 0x13 )
         nNatNum = 1;
     if ( nNatNum )
-        rString.insert( nPos, 
Concat2View("[NatNum"+OUString::number(nNatNum)+"]"));
+        rString.insert(nPos, "[NatNum" + OUString::number(nNatNum) + "]");
     return sCalendar;
 }
 
@@ -1101,11 +1101,8 @@ SvNumberformat::SvNumberformat(OUString& rString,
                         sBuff.remove(nPosOld, nPos - nPosOld);
                         if (!sStr.isEmpty())
                         {
-                            sBuff.insert(nPosOld, sStr);
-                            nPos = nPosOld + sStr.getLength();
-                            sBuff.insert(nPos, "]");
-                            sBuff.insert(nPosOld, "[");
-                            nPos += 2;
+                            sBuff.insert(nPosOld, "[" + sStr + "]");
+                            nPos = nPosOld + sStr.getLength() + 2;
                             nPosOld = nPos;     // position before string
                         }
                         else
@@ -5210,18 +5207,16 @@ static void lcl_insertLCID( OUStringBuffer& rFormatStr, 
sal_uInt32 nLCID, sal_In
         // No format code, no locale.
         return;
 
-    OUStringBuffer aLCIDString = OUString::number( nLCID , 16 
).toAsciiUpperCase();
+    auto aLCIDString = OUString::number( nLCID , 16 ).toAsciiUpperCase();
     // Search for only last DBNum which is the last element before insertion 
position
     if ( bDBNumInserted && nPosInsertLCID >= 8
-        && aLCIDString.getLength() > 4
-        && rFormatStr.indexOf( "[DBNum", nPosInsertLCID-8) == nPosInsertLCID-8 
)
+        && aLCIDString.length > 4
+        && OUString::unacquired(rFormatStr).match( "[DBNum", nPosInsertLCID-8) 
)
     {   // remove DBNumX code if long LCID
         nPosInsertLCID -= 8;
         rFormatStr.remove( nPosInsertLCID, 8 );
     }
-    aLCIDString.insert( 0, "[$-" );
-    aLCIDString.append( "]" );
-    rFormatStr.insert( nPosInsertLCID, aLCIDString );
+    rFormatStr.insert( nPosInsertLCID, "[$-" + aLCIDString + "]" );
 }
 
 /** Increment nAlphabetID for CJK numerals

Reply via email to