avmedia/source/framework/mediaitem.cxx                            |    8 +++---
 basctl/source/basicide/baside2b.cxx                               |    4 +--
 basctl/source/basicide/basobj3.cxx                                |    4 ---
 basctl/source/basicide/bastypes.cxx                               |    8 +-----
 xmloff/source/style/fonthdl.cxx                                   |    2 -
 xmloff/source/text/txtfldi.cxx                                    |    9 
+++----
 xmloff/source/transform/DocumentTContext.cxx                      |   12 
++++------
 xmloff/source/transform/TransformerBase.cxx                       |    4 ---
 xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx |    7 +++--
 xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx            |    4 +--
 xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx         |    5 ++--
 11 files changed, 29 insertions(+), 38 deletions(-)

New commits:
commit adf419792743a4c79b2054e42618dff75bb552ce
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Jul 7 13:05:57 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jul 7 15:21:33 2022 +0200

    elide some string copies
    
    Change-Id: I3e0d9f7e5a446689e007b9d01fb1c6bf9bc068e9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136880
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/avmedia/source/framework/mediaitem.cxx 
b/avmedia/source/framework/mediaitem.cxx
index 0a53cf5d4d39..7d249c604b6b 100644
--- a/avmedia/source/framework/mediaitem.cxx
+++ b/avmedia/source/framework/mediaitem.cxx
@@ -406,13 +406,13 @@ CreateStream(uno::Reference<embed::XStorage> const& 
xStorage,
 
     if (xStorage->hasByName(filename))
     {
-        OUString basename;
-        OUString suffix;
+        std::u16string_view basename;
+        std::u16string_view suffix;
         sal_Int32 const nIndex(rFilename.lastIndexOf('.'));
         if (0 < nIndex)
         {
-            basename = rFilename.copy(0, nIndex);
-            suffix = rFilename.copy(nIndex);
+            basename = rFilename.subView(0, nIndex);
+            suffix = rFilename.subView(nIndex);
         }
         sal_Int32 count(0); // sigh... try to generate non-existent name
         do
diff --git a/basctl/source/basicide/baside2b.cxx 
b/basctl/source/basicide/baside2b.cxx
index df8196570653..fbda4447191e 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -719,9 +719,9 @@ TextSelection 
EditorWindow::GetLastHighlightPortionTextSelection() const
     if( aPortions.empty() )
         return TextSelection();
 
-    OUString sStr = aLine.copy( r.nBegin, r.nEnd - r.nBegin );
+    std::u16string_view sStr = aLine.subView( r.nBegin, r.nEnd - r.nBegin );
     TextPaM aStart( nLine, r.nBegin );
-    TextPaM aEnd( nLine, r.nBegin + sStr.getLength() );
+    TextPaM aEnd( nLine, r.nBegin + sStr.size() );
     return TextSelection( aStart, aEnd );
 }
 
diff --git a/basctl/source/basicide/basobj3.cxx 
b/basctl/source/basicide/basobj3.cxx
index 26de81e35cb9..a470461be6a7 100644
--- a/basctl/source/basicide/basobj3.cxx
+++ b/basctl/source/basicide/basobj3.cxx
@@ -105,9 +105,7 @@ SbMethod* CreateMacro( SbModule* pModule, const OUString& 
rMacroName )
             aOUSource = aOUSource.copy( 0, nSourceLen-1 );
     }
 
-    OUString aSubStr = "Sub " + aMacroName + "\n\nEnd Sub";
-
-    aOUSource += aSubStr;
+    aOUSource += "Sub " + aMacroName + "\n\nEnd Sub";
 
     // update module in library
     StarBASIC* pBasic = dynamic_cast<StarBASIC*>(pModule->GetParent());
diff --git a/basctl/source/basicide/bastypes.cxx 
b/basctl/source/basicide/bastypes.cxx
index 4ebe985804d9..8d26fc4cacc8 100644
--- a/basctl/source/basicide/bastypes.cxx
+++ b/basctl/source/basicide/bastypes.cxx
@@ -584,9 +584,7 @@ void CutLines( OUString& rStr, sal_Int32 nStartLine, 
sal_Int32 nLines )
     else
         nEndPos++;
 
-    OUString aEndStr = rStr.copy( nEndPos );
-    rStr = rStr.copy( 0, nStartPos );
-    rStr += aEndStr;
+    rStr = OUString::Concat(rStr.subView( 0, nStartPos )) + rStr.subView( 
nEndPos );
 
     // erase trailing empty lines
     {
@@ -600,9 +598,7 @@ void CutLines( OUString& rStr, sal_Int32 nStartLine, 
sal_Int32 nLines )
 
         if ( n > nStartPos )
         {
-            aEndStr = rStr.copy( n );
-            rStr = rStr.copy( 0, nStartPos );
-            rStr += aEndStr;
+            rStr = OUString::Concat(rStr.subView( 0, nStartPos )) + 
rStr.subView( n );
         }
     }
 }
diff --git a/xmloff/source/style/fonthdl.cxx b/xmloff/source/style/fonthdl.cxx
index 144de999cb78..3d736a1f1a75 100644
--- a/xmloff/source/style/fonthdl.cxx
+++ b/xmloff/source/style/fonthdl.cxx
@@ -160,7 +160,7 @@ bool XMLFontFamilyNamePropHdl::exportXML( OUString& 
rStrExpValue, const uno::Any
                     sValue.append( ' ' );
                 }
                 sal_Int32 nLen = nLast-nFirst+1;
-                OUString sFamily( aStrFamilyName.copy( nFirst, nLen ) );
+                std::u16string_view sFamily( aStrFamilyName.subView( nFirst, 
nLen ) );
                 bool bQuote = false;
                 for( sal_Int32 i=0; i < nLen; i++ )
                 {
diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx
index 7e99d0c38cc9..b886823c2801 100644
--- a/xmloff/source/text/txtfldi.cxx
+++ b/xmloff/source/text/txtfldi.cxx
@@ -3323,13 +3323,12 @@ void XMLAnnotationImportContext::PrepareField(
     }
     aDateBuffer.setLength(0);
 
-    OUString sBuffer = aTextBuffer.makeStringAndClear();
-    if ( sBuffer.getLength() )
+    if ( aTextBuffer.getLength() )
     {
         // delete last paragraph mark (if necessary)
-        if (char(0x0a) == sBuffer[sBuffer.getLength()-1])
-            sBuffer = sBuffer.copy(0, sBuffer.getLength()-1);
-        xPropertySet->setPropertyValue(sAPI_content, Any(sBuffer));
+        if (char(0x0a) == aTextBuffer[aTextBuffer.getLength()-1])
+            aTextBuffer.setLength(aTextBuffer.getLength()-1);
+        xPropertySet->setPropertyValue(sAPI_content, 
Any(aTextBuffer.makeStringAndClear()));
     }
 
     if (!aName.isEmpty())
diff --git a/xmloff/source/transform/DocumentTContext.cxx 
b/xmloff/source/transform/DocumentTContext.cxx
index 894146897af7..14ad377a68fc 100644
--- a/xmloff/source/transform/DocumentTContext.cxx
+++ b/xmloff/source/transform/DocumentTContext.cxx
@@ -64,20 +64,18 @@ void XMLDocumentTransformerContext::StartElement( const 
Reference< XAttributeLis
             IsXMLToken( aLocalName, XML_MIMETYPE ) )
         {
             const OUString& rValue = xAttrList->getValueByIndex( i );
-            static const char * aTmp[] =
+            static constexpr std::string_view aTmp[]
             {
                 "application/vnd.oasis.openoffice.",
                 "application/x-vnd.oasis.openoffice.",
                 "application/vnd.oasis.opendocument.",
-                "application/x-vnd.oasis.document.",
-                nullptr
+                "application/x-vnd.oasis.document."
             };
-            for (int k=0; aTmp[k]; k++)
+            for (const auto & rPrefix : aTmp)
             {
-                OUString sTmpString = OUString::createFromAscii(aTmp[k]);
-                if( rValue.matchAsciiL( aTmp[k], sTmpString.getLength() ) )
+                if( rValue.matchAsciiL( rPrefix.data(), rPrefix.size() ) )
                 {
-                    aClass = rValue.copy( sTmpString.getLength() );
+                    aClass = rValue.copy( rPrefix.size() );
                     break;
                 }
             }
diff --git a/xmloff/source/transform/TransformerBase.cxx 
b/xmloff/source/transform/TransformerBase.cxx
index 90f8b198862a..87a6ae23836e 100644
--- a/xmloff/source/transform/TransformerBase.cxx
+++ b/xmloff/source/transform/TransformerBase.cxx
@@ -1332,11 +1332,9 @@ bool XMLTransformerBase::ConvertURIToOOo( OUString& rURI,
 
         if( bPackage && bSupportPackage )
         {
-            OUString sTmp( '#' );
             if( rURI.startsWith( "./" ) )
                 rURI = rURI.copy( 2 );
-            sTmp += rURI;
-            rURI = sTmp;
+            rURI = "#" + rURI;
             bRet = true;
         }
     }
diff --git a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx 
b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx
index 5e0ca9094b19..88bf6169bf11 100644
--- a/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx
+++ b/xmlsecurity/source/xmlsec/mscrypt/x509certificate_mscryptimpl.cxx
@@ -37,6 +37,7 @@
 #include <osl/nlsupport.h>
 #include <osl/process.h>
 #include <o3tl/char16_t2wchar_t.hxx>
+#include <o3tl/string_view.hxx>
 
 #include <memory>
 #include <string_view>
@@ -77,9 +78,9 @@ findTypeInDN(const OUString& rRawString, std::u16string_view 
sTypeName)
         {
             if (! bInValue)
             {
-                OUString sType = rRawString.copy(nTypeNameStart, i - 
nTypeNameStart);
-                sType = sType.trim();
-                if (sType.equalsIgnoreAsciiCase(sTypeName))
+                std::u16string_view sType = rRawString.subView(nTypeNameStart, 
i - nTypeNameStart);
+                sType = o3tl::trim(sType);
+                if (o3tl::equalsIgnoreAsciiCase(sType, sTypeName))
                 {
                     bFound = true;
                     break;
diff --git a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx 
b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
index e37a5473ceb8..1395cb2e8acb 100644
--- a/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/sanextension_nssimpl.cxx
@@ -152,9 +152,9 @@ css::uno::Sequence< css::security::CertAltNameEntry > 
SAL_CALL SanExtensionImpl:
 OString SanExtensionImpl::removeOIDFromString( const OString &oidString)
 {
     OString objID;
-    OString oid("OID.");
+    constexpr std::string_view oid("OID.");
     if (oidString.match(oid))
-        objID = oidString.copy(oid.getLength());
+        objID = oidString.copy(oid.size());
     else
         objID = oidString;
     return objID;
diff --git a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx 
b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
index 7e28cbc615bd..e1b62e13c0f5 100644
--- a/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
+++ b/xmlsecurity/source/xmlsec/nss/x509certificate_nssimpl.cxx
@@ -36,6 +36,7 @@
 #include <certificateextension_xmlsecimpl.hxx>
 
 #include "sanextension_nssimpl.hxx"
+#include <o3tl/string_view.hxx>
 #include <tools/time.hxx>
 #include <svl/sigstruct.hxx>
 
@@ -185,9 +186,9 @@ css::uno::Sequence< css::uno::Reference< 
css::security::XCertificateExtension >
 
             // remove "OID." prefix if existing
             OString objID;
-            OString oid("OID.");
+            constexpr std::string_view oid("OID.");
             if (oidString.match(oid))
-                objID = oidString.copy(oid.getLength());
+                objID = oidString.copy(oid.size());
             else
                 objID = oidString;
 

Reply via email to