editeng/source/editeng/ContentNode.cxx |    5 +----
 include/rtl/ustring.hxx                |   14 +++++++++++---
 sal/osl/w32/file_url.cxx               |    2 +-
 stoc/source/security/permissions.cxx   |    3 +--
 4 files changed, 14 insertions(+), 10 deletions(-)

New commits:
commit 550ef55881f992b53f860b7f29f4716846779ea0
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Wed Jul 31 11:07:14 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Wed Jul 31 12:15:38 2024 +0200

    Reintroduce OUString::replaceAt taking an OUString to LIBO_INTERNAL_ONLY
    
    This allows optimizations when 'this' is empty, avoiding allocations, and
    making it possible to not special-case it in other places, as was done in
    ContentNode::Insert in commit 8ab44b114c6706ab2e3d8a19884daeb544d3c2e1
    (tdf#161846 avoid allocation in ContentNode::Insert, 2024-07-30).
    
    A couple of disambiguation templated overloads was introduced.
    
    Change-Id: I2b5e94c2175379b2696c34e600393d32731f0ab6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171271
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/editeng/source/editeng/ContentNode.cxx 
b/editeng/source/editeng/ContentNode.cxx
index de5e2150b151..b7e7f4b0e8ee 100644
--- a/editeng/source/editeng/ContentNode.cxx
+++ b/editeng/source/editeng/ContentNode.cxx
@@ -564,10 +564,7 @@ void ContentNode::SetChar(sal_Int32 nPos, sal_Unicode c)
 
 void ContentNode::Insert(const OUString& rStr, sal_Int32 nPos)
 {
-    if (nPos == 0 && maString.getLength() == 0)
-        maString = rStr; // avoid allocation
-    else
-        maString = maString.replaceAt(nPos, 0, rStr);
+    maString = maString.replaceAt(nPos, 0, rStr);
 }
 
 void ContentNode::Append(std::u16string_view rStr)
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index d4f54f76a1f6..3a6531b4f3a5 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -2631,8 +2631,6 @@ public:
     }
 #endif
 
-// hide this from internal code to avoid ambiguous lookup error
-#ifndef LIBO_INTERNAL_ONLY
     /**
       Returns a new string resulting from replacing n = count characters
       from position index in this string with newStr.
@@ -2652,7 +2650,6 @@ public:
         rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData 
);
         return OUString( pNew, SAL_NO_ACQUIRE );
     }
-#endif
 
 #ifdef LIBO_INTERNAL_ONLY
     SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 
count, std::u16string_view newStr ) const
@@ -2661,6 +2658,17 @@ public:
         rtl_uString_newReplaceStrAtUtf16L( &pNew, pData, index, count, 
newStr.data(), newStr.size() );
         return OUString( pNew, SAL_NO_ACQUIRE );
     }
+    // Disambiguation
+    template <std::size_t N>
+    SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 
count, const sal_Unicode (&newStr)[N] ) const
+    {
+        return replaceAt(index, count, std::u16string_view(newStr, N - 1));
+    }
+    template <class T, std::enable_if_t<std::is_convertible_v<T, 
std::u16string_view>, int> = 0>
+    SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 
count, const T& newStr ) const
+    {
+        return replaceAt(index, count, std::u16string_view(newStr));
+    }
 #endif
 
     /**
diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx
index e074fbff54e6..82428a326621 100644
--- a/sal/osl/w32/file_url.cxx
+++ b/sal/osl/w32/file_url.cxx
@@ -424,7 +424,7 @@ DWORD IsValidFilePath(const OUString& path, DWORD dwFlags, 
OUString* corrected)
             // Correct path by merging consecutive slashes:
             if (o3tl::starts_with(*oComponent, u"\") && corrected != nullptr) {
                 sal_Int32 i = oComponent->data() - lastCorrected.getStr();
-                *corrected = lastCorrected.replaceAt(i, 1, {});
+                *corrected = lastCorrected.replaceAt(i, 1, 
std::u16string_view{});
                     //TODO: handle out-of-memory
                 lastCorrected = *corrected;
                 oComponent = lastCorrected.subView(i);
diff --git a/stoc/source/security/permissions.cxx 
b/stoc/source/security/permissions.cxx
index 77da8459987b..b99aa9420a59 100644
--- a/stoc/source/security/permissions.cxx
+++ b/stoc/source/security/permissions.cxx
@@ -327,9 +327,8 @@ FilePermission::FilePermission(
     // correct win drive letters
     if (9 < m_url.getLength() && '|' == m_url[ 9 ]) // file:///X|
     {
-        constexpr OUStringLiteral s_colon = u":";
         // common case in API is a ':' (sal), so convert '|' to ':'
-        m_url = m_url.replaceAt( 9, 1, s_colon );
+        m_url = m_url.replaceAt(9, 1, u":");
     }
 #endif
 }

Reply via email to