extensions/source/propctrlr/browserline.cxx |    2 +-
 include/rtl/ustrbuf.hxx                     |    5 +++++
 include/rtl/ustring.hxx                     |   16 ++++++++++++++++
 sc/source/core/tool/compiler.cxx            |    2 +-
 svl/source/numbers/zformat.cxx              |    2 +-
 svtools/source/svrtf/parrtf.cxx             |    2 +-
 sw/source/filter/ww8/ww8par2.cxx            |    2 +-
 tools/source/fsys/urlobj.cxx                |    6 ++----
 vcl/source/control/field.cxx                |    4 ++--
 9 files changed, 30 insertions(+), 11 deletions(-)

New commits:
commit 9f4aad493c7087256d03b01ca3fb18d96f461526
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Dec 26 09:11:53 2021 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Jan 2 09:03:32 2022 +0100

    Introduce OUString::unacquired(const OUStringBuffer&)
    
    ... and avoid OUStringBuffer::toString when the temporary is used
    for checking current buffer content
    
    Change-Id: I114178f3e74ca3e4a3e517763f9eaab4797b7deb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127478
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/extensions/source/propctrlr/browserline.cxx 
b/extensions/source/propctrlr/browserline.cxx
index a42b63c10e9b..814c24f4b306 100644
--- a/extensions/source/propctrlr/browserline.cxx
+++ b/extensions/source/propctrlr/browserline.cxx
@@ -179,7 +179,7 @@ namespace pcr
         OUStringBuffer aText(m_xFtTitle->get_label());
 
         int n10DotsWidth = m_xFtTitle->get_pixel_size("..........").Width();
-        int nTextWidth = m_xFtTitle->get_pixel_size(aText.toString()).Width();
+        int nTextWidth = 
m_xFtTitle->get_pixel_size(OUString::unacquired(aText)).Width();
         int nDiff = m_nNameWidth - nTextWidth;
         int nExtraChars = (nDiff * 10) / n10DotsWidth;
         for (int i = 0; i < nExtraChars; ++i)
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 85fe744e9ee1..d35200643e01 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -1765,6 +1765,11 @@ template<> struct ToStringHelper<OUStringBuffer> {
         else
             return internalAppend(str.pData);
     }
+
+    inline OUString const& OUString::unacquired(const OUStringBuffer& str)
+    {
+        return unacquired(&str.pData);
+    }
 #endif
 }
 
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 13cc367c5589..cad257caeb58 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -541,6 +541,22 @@ public:
     static OUString const & unacquired( rtl_uString * const * ppHandle )
         { return * reinterpret_cast< OUString const * >( ppHandle ); }
 
+#if defined LIBO_INTERNAL_ONLY
+    /** Provides an OUString const & passing an OUStringBuffer const reference.
+        It is more convenient to use C++ OUString member functions when 
checking
+        current buffer content. Use this function instead of toString (that
+        allocates a new OUString from buffer data) when the result is used in
+        comparisons.
+
+        @param str
+               an OUStringBuffer
+        @return
+               OUString const & based on given storage
+        @since LibreOffice 7.4
+    */
+    static OUString const& unacquired(const OUStringBuffer& str);
+#endif
+
     /**
       Assign a new string.
 
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 42385b3441cf..0858487b2836 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -666,7 +666,7 @@ static bool lcl_parseExternalName(
     if (aTmpName[nNameLen-1] == '!')
     {
         // Check against #REF!.
-        if (aTmpName.toString().equalsIgnoreAsciiCase("#REF!"))
+        if (OUString::unacquired(aTmpName).equalsIgnoreAsciiCase("#REF!"))
             return false;
     }
 
diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx
index 4b1e2a48c152..3e08154f222a 100644
--- a/svl/source/numbers/zformat.cxx
+++ b/svl/source/numbers/zformat.cxx
@@ -2673,7 +2673,7 @@ bool SvNumberformat::ImpGetScientificOutput(double 
fNumber,
 
         if ( rInfo.nCntPre != 1 ) // rescale Exp
         {
-            sal_Int32 nExp = ExpStr.toString().toInt32() * nExpSign;
+            sal_Int32 nExp = OUString::unacquired(ExpStr).toInt32() * nExpSign;
             sal_Int32 nRescale = (rInfo.nCntPre != 0) ? nExp % 
static_cast<sal_Int32>(rInfo.nCntPre) : -1;
             if( nRescale < 0 && rInfo.nCntPre != 0 )
                 nRescale += static_cast<sal_Int32>(rInfo.nCntPre);
diff --git a/svtools/source/svrtf/parrtf.cxx b/svtools/source/svrtf/parrtf.cxx
index ef6cdbb73620..d16ac8cf0a1e 100644
--- a/svtools/source/svrtf/parrtf.cxx
+++ b/svtools/source/svrtf/parrtf.cxx
@@ -125,7 +125,7 @@ int SvRTFParser::GetNextToken_()
                                 
aNumber.append(static_cast<sal_Unicode>(nNextCh));
                                 nNextCh = GetNextChar();
                             } while( RTF_ISDIGIT( nNextCh ) );
-                            nTokenValue = aNumber.toString().toInt32();
+                            nTokenValue = 
OUString::unacquired(aNumber).toInt32();
                             if( bNegValue )
                                 nTokenValue = -nTokenValue;
                             bTokenHasValue=true;
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index 69bed2580eca..a50e0b1d280c 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -708,7 +708,7 @@ void SwWW8ImplReader::SetAnlvStrings(SwNumFormat &rNum, int 
nLevel, WW8_ANLV con
                 if (rAV.cbTextBefore || rAV.cbTextAfter)
                 {
                     rNum.SetBulletChar(
-                        
sText.toString().iterateCodePoints(&o3tl::temporary(sal_Int32(0))));
+                        
OUString::unacquired(sText).iterateCodePoints(&o3tl::temporary(sal_Int32(0))));
                 }
                 else
                     rNum.SetBulletChar( 0x2190 );
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index 0ab541147357..49d0500cabb0 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -2888,8 +2888,7 @@ bool INetURLObject::setHost(std::u16string_view rTheHost,
     {
         case INetProtocol::File:
             {
-                OUString sTemp(aSynHost.toString());
-                if (sTemp.equalsIgnoreAsciiCase("localhost"))
+                if 
(OUString::unacquired(aSynHost).equalsIgnoreAsciiCase("localhost"))
                 {
                     aSynHost.setLength(0);
                 }
@@ -3804,8 +3803,7 @@ bool INetURLObject::ConcatData(INetProtocol eTheScheme,
             {
                 case INetProtocol::File:
                     {
-                        OUString sTemp(aSynHost.toString());
-                        if (sTemp.equalsIgnoreAsciiCase( "localhost" ))
+                        if 
(OUString::unacquired(aSynHost).equalsIgnoreAsciiCase( "localhost" ))
                         {
                             aSynHost.setLength(0);
                         }
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index cc5a6330d1a9..7fabe96d400a 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -794,13 +794,13 @@ namespace
         nTextLen = OUString(OUString::number(rFormatter.GetMin())).getLength();
         string::padToLength(aBuf, nTextLen, '9');
         Size aMinTextSize = rSpinField.CalcMinimumSizeForText(
-            rFormatter.CreateFieldText(aBuf.toString().toInt64()));
+            rFormatter.CreateFieldText(OUString::unacquired(aBuf).toInt64()));
         aBuf.setLength(0);
 
         nTextLen = OUString(OUString::number(rFormatter.GetMax())).getLength();
         string::padToLength(aBuf, nTextLen, '9');
         Size aMaxTextSize = rSpinField.CalcMinimumSizeForText(
-            rFormatter.CreateFieldText(aBuf.toString().toInt64()));
+            rFormatter.CreateFieldText(OUString::unacquired(aBuf).toInt64()));
         aBuf.setLength(0);
 
         Size aRet(std::max(aMinTextSize.Width(), aMaxTextSize.Width()),

Reply via email to