summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-09-30 13:54:26 +0200
committerStephan Bergmann <sbergman@redhat.com>2021-10-03 19:50:44 +0200
commitad1557f5d775739230e0e2252c293948977b42a0 (patch)
tree610e2e849d87583888c0c658088044d6dc3966a5 /sal
parent7e7dd7f152bc7457437f541e7ff88d69e9f8e765 (diff)
A more lightweight O[U]StringConcatenation
...compared to a full-blown O[U]String, for temporary objects holding an O[U]StringConcat result that can then be used as a std::[u16]string_view. It's instructive to see how some invocations of operator ==, operator !=, and O[U]StringBuffer::insert with an O[U]StringConcat argument required implicit materialization of an O[U]String temporary, and how that expensive operation has now been made explicit with the explicit O[U]StringConcatenation ctor. (The additional operator == and operator != overloads are necessary because the overloads taking two std::[u16]string_view parameters wouldn't even be found here with ADL. And the OUString-related ones would cause ambiguities in at least sal/qa/rtl/strings/test_oustring_stringliterals.cxx built with RTL_STRING_UNITTEST, so have simply been disabled for that special test-code case.) Change-Id: Id29799fa8da21a09ff9794cbc7cc9b366e6803b8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122890 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r--sal/qa/rtl/strings/test_oustring_compare.cxx4
-rw-r--r--sal/qa/rtl/textenc/rtl_textcvt.cxx34
2 files changed, 19 insertions, 19 deletions
diff --git a/sal/qa/rtl/strings/test_oustring_compare.cxx b/sal/qa/rtl/strings/test_oustring_compare.cxx
index 6316f09b1d58..e55d4d3d93b1 100644
--- a/sal/qa/rtl/strings/test_oustring_compare.cxx
+++ b/sal/qa/rtl/strings/test_oustring_compare.cxx
@@ -88,8 +88,8 @@ void test::oustring::Compare::compareTo()
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), s2.compareTo(s2));
CPPUNIT_ASSERT(s1.compareTo(s2) < 0);
CPPUNIT_ASSERT(s2.compareTo(s1) > 0);
- CPPUNIT_ASSERT(s1.compareTo(OUString(s2 + "y")) < 0);
- CPPUNIT_ASSERT(s2.compareTo(OUString(s1 + "x")) > 0);
+ CPPUNIT_ASSERT(s1.compareTo(OUStringConcatenation(s2 + "y")) < 0);
+ CPPUNIT_ASSERT(s2.compareTo(OUStringConcatenation(s1 + "x")) > 0);
CPPUNIT_ASSERT(OUString(s1 + "x").compareTo(s2) < 0);
CPPUNIT_ASSERT(OUString(s2 + "y").compareTo(s1) > 0);
}
diff --git a/sal/qa/rtl/textenc/rtl_textcvt.cxx b/sal/qa/rtl/textenc/rtl_textcvt.cxx
index e4cdbc84c248..8fa8b4e8dc96 100644
--- a/sal/qa/rtl/textenc/rtl_textcvt.cxx
+++ b/sal/qa/rtl/textenc/rtl_textcvt.cxx
@@ -56,7 +56,7 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
{
rtl_TextToUnicodeConverter aConverter
= rtl_createTextToUnicodeConverter(rSet.m_nEncoding);
- CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::number(rSet.m_nEncoding) + ") failed"),
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUStringConcatenation("rtl_createTextToUnicodeConverter(" + OUString::number(rSet.m_nEncoding) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != nullptr);
rtl_TextToUnicodeContext aContext
@@ -81,11 +81,11 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
int j = 0;
for (int i = 0; i < 256; ++i) {
if (rSet.m_aMap[i] != 0xFFFF && aUnicode[j] != rSet.m_aMap[i]) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("rSet.m_aMap[" + OUString::number(i) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("rSet.m_aMap[" + OUString::number(i) + "] == " +
OUString::number(rSet.m_aMap[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(),
u'\xFFFF', rSet.m_aMap[i]);
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(j) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("aUnicode[" + OUString::number(j) + "] == " +
OUString::number(aUnicode[j], 16) +
", rSet.m_aMap[" + OUString::number(i) + "] == " +
OUString::number(rSet.m_aMap[i], 16)),
@@ -102,7 +102,7 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
{
rtl_UnicodeToTextConverter aConverter
= rtl_createUnicodeToTextConverter(rSet.m_nEncoding);
- CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"),
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUStringConcatenation("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != nullptr);
rtl_UnicodeToTextContext aContext
@@ -128,11 +128,11 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
if (rSet.m_aMap[i] != 0xFFFF
&& aText[j] != static_cast< char >(i))
{
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("rSet.m_aMap[" + OUString::number(i) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("rSet.m_aMap[" + OUString::number(i) + "] == " +
OUString::number(rSet.m_aMap[i], 16)),
RTL_TEXTENCODING_UTF8).getStr(),
u'\xFFFF', rSet.m_aMap[i]);
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aText[" + OUString::number(j) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("aText[" + OUString::number(j) + "] == " +
OUString::number(i, 16)),
RTL_TEXTENCODING_UTF8).getStr(),
static_cast< char >(i), aText[j]);
@@ -146,7 +146,7 @@ void testSingleByteCharSet(SingleByteCharSet const & rSet) {
aText[0] = static_cast< char >(i);
rtl_TextToUnicodeConverter aConverter
= rtl_createTextToUnicodeConverter(rSet.m_nEncoding);
- CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"),
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUStringConcatenation("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rSet.m_nEncoding)) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != nullptr);
rtl_TextToUnicodeContext aContext
@@ -194,7 +194,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
sal_Unicode aUnicode[TEST_STRING_SIZE];
rtl_TextToUnicodeConverter aConverter
= rtl_createTextToUnicodeConverter(rTest.m_nEncoding);
- CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUStringConcatenation("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != nullptr);
rtl_TextToUnicodeContext aContext
@@ -222,7 +222,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
rtl_destroyTextToUnicodeConverter(aConverter);
for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("aUnicode[" + OUString::number(i) + "] == " +
OUString::number(aUnicode[i], 16) +
", rTest.m_aUnicode[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_aUnicode[i], 16)),
@@ -234,7 +234,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
sal_Unicode aUnicode[TEST_STRING_SIZE];
rtl_TextToUnicodeConverter aConverter
= rtl_createTextToUnicodeConverter(rTest.m_nEncoding);
- CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUStringConcatenation("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != nullptr);
rtl_TextToUnicodeContext aContext
@@ -272,7 +272,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
CPPUNIT_ASSERT_EQUAL(rTest.m_nTextSize, nInput);
for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("aUnicode[" + OUString::number(i) + "] == " +
OUString::number(aUnicode[i], 16) +
", rTest.m_aUnicode[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_aUnicode[i], 16)),
@@ -288,7 +288,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
int nSize = 0;
rtl_TextToUnicodeConverter aConverter
= rtl_createTextToUnicodeConverter(rTest.m_nEncoding);
- CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUStringConcatenation("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != nullptr);
for (sal_Size i = 0;;) {
@@ -357,7 +357,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
done:
rtl_destroyTextToUnicodeConverter(aConverter);
for (sal_Size i = 0; i < rTest.m_nUnicodeSize; ++i) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("aUnicode[" + OUString::number(i) + "] == " +
OUString::number(aUnicode[i], 16) +
", rTest.m_aUnicode[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_aUnicode[i], 16)),
@@ -369,7 +369,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
char aText[TEST_STRING_SIZE];
rtl_UnicodeToTextConverter aConverter
= rtl_createUnicodeToTextConverter(rTest.m_nEncoding);
- CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUStringConcatenation("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != nullptr);
rtl_UnicodeToTextContext aContext
@@ -397,7 +397,7 @@ void doComplexCharSetTest(ComplexCharSetTest const & rTest) {
rtl_destroyUnicodeToTextContext(aConverter, aContext);
rtl_destroyUnicodeToTextConverter(aConverter);
for (sal_Size i = 0; i < rTest.m_nTextSize; ++i) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aText[" + OUString::number(i) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("aText[" + OUString::number(i) + "] == " +
OUString::number(aText[i], 16) +
", rTest.m_pText[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_pText[i], 16)),
@@ -412,7 +412,7 @@ void doComplexCharSetCutTest(ComplexCharSetTest const & rTest) {
sal_Unicode aUnicode[TEST_STRING_SIZE];
rtl_TextToUnicodeConverter aConverter
= rtl_createTextToUnicodeConverter(rTest.m_nEncoding);
- CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUString("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
+ CPPUNIT_ASSERT_MESSAGE(OUStringToOString(OUStringConcatenation("rtl_createTextToUnicodeConverter(" + OUString::createFromAscii(rtl_getMimeCharsetFromTextEncoding(rTest.m_nEncoding)) + ") failed"),
RTL_TEXTENCODING_UTF8).getStr(),
aConverter != nullptr);
sal_Size nSize;
@@ -436,7 +436,7 @@ void doComplexCharSetCutTest(ComplexCharSetTest const & rTest) {
rtl_destroyTextToUnicodeConverter(aConverter);
for (sal_Size i = 0; i < nSize; ++i) {
- CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUString("aUnicode[" + OUString::number(i) + "] == " +
+ CPPUNIT_ASSERT_EQUAL_MESSAGE(OUStringToOString(OUStringConcatenation("aUnicode[" + OUString::number(i) + "] == " +
OUString::number(aUnicode[i], 16) +
", rTest.m_aUnicode[" + OUString::number(i) + "] == " +
OUString::number(rTest.m_aUnicode[i], 16)),