[Libreoffice-commits] .: sal/inc sal/qa

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Dec 4 02:20:44 PST 2012


 sal/inc/rtl/string.hxx                      |    7 +++++--
 sal/inc/rtl/ustring.hxx                     |    9 ++++++---
 sal/qa/rtl/strings/test_ostring_concat.cxx  |    1 +
 sal/qa/rtl/strings/test_oustring_concat.cxx |    1 +
 4 files changed, 13 insertions(+), 5 deletions(-)

New commits:
commit 4e593d047b9c10de085dffa3fa3dd4602361c407
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Dec 4 11:20:22 2012 +0100

    Fix fast concat of empty strings
    
    Change-Id: Ice9c6974f44be3bc4c9b3533de2a9beb5b146ca5

diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index 2c7a43d..aeb7528 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -262,8 +262,11 @@ public:
         const int l = c.length();
         rtl_String* buffer = NULL;
         rtl_string_new_WithLength( &buffer, l );
-        char* end = c.addData( buffer->buffer );
-        buffer->length = end - buffer->buffer;
+        if (l != 0)
+        {
+            char* end = c.addData( buffer->buffer );
+            buffer->length = end - buffer->buffer;
+        }
         pData = buffer;
     }
 #endif
diff --git a/sal/inc/rtl/ustring.hxx b/sal/inc/rtl/ustring.hxx
index 534bd88..ec9f90e 100644
--- a/sal/inc/rtl/ustring.hxx
+++ b/sal/inc/rtl/ustring.hxx
@@ -330,9 +330,12 @@ public:
         const int l = c.length();
         rtl_uString* buffer = NULL;
         rtl_uString_new_WithLength( &buffer, l ); // TODO this clears, not necessary
-        sal_Unicode* end = c.addData( buffer->buffer );
-        buffer->length = end - buffer->buffer;
-        // TODO realloc in case buffer->length is noticeably smaller than l ?
+        if (l != 0)
+        {
+            sal_Unicode* end = c.addData( buffer->buffer );
+            buffer->length = end - buffer->buffer;
+            // TODO realloc in case buffer->length is noticeably smaller than l?
+        }
         pData = buffer;
     }
 #endif
diff --git a/sal/qa/rtl/strings/test_ostring_concat.cxx b/sal/qa/rtl/strings/test_ostring_concat.cxx
index a79b2da..46457dd 100644
--- a/sal/qa/rtl/strings/test_ostring_concat.cxx
+++ b/sal/qa/rtl/strings/test_ostring_concat.cxx
@@ -47,6 +47,7 @@ CPPUNIT_TEST_SUITE_END();
 void test::ostring::StringConcat::check()
 {
 // All the extra () are to protect commas againsts being treated as separators of macro arguments.
+    CPPUNIT_ASSERT_EQUAL( OString(), OString(OString() + OString()) );
     CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OString( "foo" ) + OString( "bar" )));
     TYPES_ASSERT_EQUAL(( typeid( OStringConcat< OString, OString > )), typeid( OString( "foo" ) + OString( "bar" )));
     CPPUNIT_ASSERT_EQUAL( OString( "foobar" ), OString( OString( "foo" ) + "bar" ));
diff --git a/sal/qa/rtl/strings/test_oustring_concat.cxx b/sal/qa/rtl/strings/test_oustring_concat.cxx
index 0cc2512..4f650dc 100644
--- a/sal/qa/rtl/strings/test_oustring_concat.cxx
+++ b/sal/qa/rtl/strings/test_oustring_concat.cxx
@@ -47,6 +47,7 @@ CPPUNIT_TEST_SUITE_END();
 void test::oustring::StringConcat::check()
 {
 // All the extra () are to protect commas againsts being treated as separators of macro arguments.
+    CPPUNIT_ASSERT_EQUAL( OUString(), OUString(OUString() + OUString()) );
     CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUString( "foo" ) + OUString( "bar" )));
     TYPES_ASSERT_EQUAL(( typeid( OUStringConcat< OUString, OUString > )), typeid( OUString( "foo" ) + OUString( "bar" )));
     CPPUNIT_ASSERT_EQUAL( OUString( "foobar" ), OUString( OUString( "foo" ) + "bar" ));


More information about the Libreoffice-commits mailing list