summaryrefslogtreecommitdiff
path: root/include/rtl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-07-31 13:13:36 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-01 21:39:28 +0200
commit28580110807a38e3ba6f8385f22871b8dfe0a910 (patch)
tree33ff5f3c25316926f14ffbb837025090465c2a2a /include/rtl
parent58e266ae808dbf3e157b38eb2c8f24774131e0f8 (diff)
add operator+=(OUStringBuffer) method to OUString
to reduce needless object creation and copying some more And fix what looks like a bug in CSS hex color parsing at line 609 in sw/../parcss1.cxx that has been there since commit 7b0b5cdfeed656b279bc32cd929630d5fc25878b "initial import" Change-Id: Ibad42b23721a56493bd1edcd7165e6104494a5c3 Reviewed-on: https://gerrit.libreoffice.org/58357 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/rtl')
-rw-r--r--include/rtl/ustrbuf.hxx13
-rw-r--r--include/rtl/ustring.hxx37
2 files changed, 42 insertions, 8 deletions
diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx
index 1a40eeee8832..5f696bff906d 100644
--- a/include/rtl/ustrbuf.hxx
+++ b/include/rtl/ustrbuf.hxx
@@ -59,6 +59,7 @@ namespace rtl
*/
class SAL_WARN_UNUSED OUStringBuffer
{
+friend class OUString;
public:
/**
Constructs a string buffer with no characters in it and an
@@ -1615,6 +1616,18 @@ private:
sal_Int32 nCapacity;
};
+#if defined LIBO_INTERNAL_ONLY
+ // Define this here to avoid circular includes
+ inline OUString & OUString::operator+=( const OUStringBuffer & str ) &
+ {
+ // Call operator= if this is empty, otherwise rtl_uString_newConcat will attempt to
+ // acquire() the str.pData buffer, which is part of the OUStringBuffer mutable state.
+ if (isEmpty())
+ return operator=(str.toString());
+ else
+ return internalAppend(str.pData);
+ }
+#endif
}
#ifdef RTL_STRING_UNITTEST
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index 1731bb905c76..24005b22333d 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -56,6 +56,8 @@ extern bool rtl_string_unittest_invalid_conversion;
namespace rtl
{
+class OUStringBuffer;
+
#ifdef RTL_STRING_UNITTEST
#undef rtl
#endif
@@ -516,6 +518,18 @@ public:
}
#endif
+#if defined LIBO_INTERNAL_ONLY
+ /**
+ Append the contents of an OUStringBuffer to this string.
+
+ @param str an OUStringBuffer.
+
+ @exception std::bad_alloc is thrown if an out-of-memory condition occurs
+ @since LibreOffice 6.2
+ */
+ inline OUString & operator+=( const OUStringBuffer & str ) &;
+#endif
+
/**
Append a string to this string.
@@ -528,14 +542,7 @@ public:
&
#endif
{
- rtl_uString* pNewData = NULL;
- rtl_uString_newConcat( &pNewData, pData, str.pData );
- if (pNewData == NULL) {
- throw std::bad_alloc();
- }
- rtl_uString_assign(&pData, pNewData);
- rtl_uString_release(pNewData);
- return *this;
+ return internalAppend(str.pData);
}
#if defined LIBO_INTERNAL_ONLY
void operator+=(OUString const &) && = delete;
@@ -3539,6 +3546,20 @@ public:
rtl_uString_newFromAscii( &pNew, value );
return OUString( pNew, SAL_NO_ACQUIRE );
}
+
+private:
+ OUString & internalAppend( rtl_uString* pOtherData )
+ {
+ rtl_uString* pNewData = NULL;
+ rtl_uString_newConcat( &pNewData, pData, pOtherData );
+ if (pNewData == NULL) {
+ throw std::bad_alloc();
+ }
+ rtl_uString_assign(&pData, pNewData);
+ rtl_uString_release(pNewData);
+ return *this;
+ }
+
};
#if defined LIBO_INTERNAL_ONLY