diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-06-26 13:49:25 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-06-26 13:55:30 +0200 |
commit | edc96a157e3ab8b54046ee28df947a43330d3d3f (patch) | |
tree | f941a95670bcaed98194babba77fee143f57e1b1 /sal | |
parent | 1de776a4927aa2c1e525ce28764f076061f2c8cd (diff) |
Add optimized OUString += literal overload
Change-Id: Ib34196185f90204a71598f2c659c3fddce7a0e4d
Diffstat (limited to 'sal')
-rw-r--r-- | sal/qa/rtl/strings/test_oustring_concat.cxx | 8 | ||||
-rw-r--r-- | sal/rtl/ustring.cxx | 24 | ||||
-rw-r--r-- | sal/util/sal.map | 1 |
3 files changed, 33 insertions, 0 deletions
diff --git a/sal/qa/rtl/strings/test_oustring_concat.cxx b/sal/qa/rtl/strings/test_oustring_concat.cxx index f02bde560451..977229691702 100644 --- a/sal/qa/rtl/strings/test_oustring_concat.cxx +++ b/sal/qa/rtl/strings/test_oustring_concat.cxx @@ -40,12 +40,14 @@ class StringConcat : public CppUnit::TestFixture { private: void checkConcat(); + void checkConcatAsciiL(); void checkEnsureCapacity(); void checkAppend(); void checkInvalid(); CPPUNIT_TEST_SUITE(StringConcat); CPPUNIT_TEST(checkConcat); +CPPUNIT_TEST(checkConcatAsciiL); CPPUNIT_TEST(checkEnsureCapacity); CPPUNIT_TEST(checkAppend); CPPUNIT_TEST(checkInvalid); @@ -71,6 +73,12 @@ void test::oustring::StringConcat::checkConcat() CPPUNIT_ASSERT_EQUAL(( typeid( OUStringConcat< OUStringBuffer, OUString > )), typeid( OUStringBuffer( "foo" ) + OUString( "bar" ))); } +void test::oustring::StringConcat::checkConcatAsciiL() +{ + CPPUNIT_ASSERT_EQUAL(OUString("foo"), OUString("foo") += ""); + CPPUNIT_ASSERT_EQUAL(OUString("foobar"), OUString("foo") += "bar"); +} + void test::oustring::StringConcat::checkEnsureCapacity() { rtl_uString* str = NULL; diff --git a/sal/rtl/ustring.cxx b/sal/rtl/ustring.cxx index de733e86be0d..b31bc2fcddeb 100644 --- a/sal/rtl/ustring.cxx +++ b/sal/rtl/ustring.cxx @@ -25,6 +25,8 @@ #include <cassert> #include <cstdlib> +#include <limits> +#include <stdexcept> #include <osl/diagnose.h> #include <osl/interlck.h> @@ -595,6 +597,28 @@ void SAL_CALL rtl_uString_newFromCodePoints( RTL_LOG_STRING_NEW( *newString ); } +void rtl_uString_newConcatAsciiL( + rtl_uString ** newString, rtl_uString * left, char const * right, + sal_Int32 rightLength) +{ + assert(newString != nullptr); + assert(left != nullptr); + assert(right != nullptr); + assert(rightLength >= 0); + if (left->length > std::numeric_limits<sal_Int32>::max() - rightLength) { + throw std::length_error("rtl_uString_newConcatAsciiL"); + } + sal_Int32 n = left->length + rightLength; + rtl_uString_assign(newString, left); + rtl_uString_ensureCapacity(newString, n); + sal_Unicode * p = (*newString)->buffer + (*newString)->length; + for (sal_Int32 i = 0; i != rightLength; ++i) { + p[i] = static_cast<unsigned char>(right[i]); + } + (*newString)->buffer[n] = 0; + (*newString)->length = n; +} + /* ======================================================================= */ static int rtl_ImplGetFastUTF8UnicodeLen( const sal_Char* pStr, sal_Int32 nLen, bool * ascii ) diff --git a/sal/util/sal.map b/sal/util/sal.map index c41ee41ebc7e..e3f920c7e33c 100644 --- a/sal/util/sal.map +++ b/sal/util/sal.map @@ -685,6 +685,7 @@ LIBO_UDK_5.0 { # symbols available in >= LibO 5.0 LIBO_UDK_5.1 { # symbols available in >= LibO 5.1 global: + rtl_uString_newConcatAsciiL; rtl_uString_newReplaceAllToAsciiL; rtl_uString_newReplaceFirstToAsciiL; } LIBO_UDK_5.0; |