diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-13 08:47:47 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-10-14 08:26:14 +0200 |
commit | 9b5dad13b56bdde7c40970351af3da3a2c3c9350 (patch) | |
tree | abfd4b02743a0e6a93c51c026f4c53f0e21100bc /include/rtl | |
parent | fa71320329999c968feb16ff65be328b5b8ff5e4 (diff) |
loplugin:stringadd look for unnecessary temporaries
which defeat the *StringConcat optimisation.
Also make StringConcat conversions treat a nullptr as an empty string,
to match the O*String(char*) constructors.
Change-Id: If45f5b4b6a535c97bfeeacd9ec472a7603a52e5b
Reviewed-on: https://gerrit.libreoffice.org/80724
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/stringconcat.hxx | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/include/rtl/stringconcat.hxx b/include/rtl/stringconcat.hxx index b751c020e75b..3fd8b6720851 100644 --- a/include/rtl/stringconcat.hxx +++ b/include/rtl/stringconcat.hxx @@ -113,9 +113,11 @@ template<> struct ToStringHelper< const char* > { static std::size_t length( const char* str ) { - return strlen( str ); + return str ? strlen( str ) : 0; + } + static char* addData( char* buffer, const char* str ) { + return str ? addDataCString( buffer, str ) : buffer; } - static char* addData( char* buffer, const char* str ) { return addDataCString( buffer, str ); } static const bool allowOStringConcat = true; static const bool allowOUStringConcat = false; }; @@ -148,9 +150,11 @@ template<> struct ToStringHelper< const sal_Unicode* > { static std::size_t length( const sal_Unicode* str ) { - return std::char_traits<char16_t>::length( str ); + return str ? std::char_traits<char16_t>::length( str ) : 0; + } + static sal_Unicode* addData( sal_Unicode* buffer, const sal_Unicode* str ) { + return str ? addDataUString( buffer, str ) : buffer; } - static sal_Unicode* addData( sal_Unicode* buffer, const sal_Unicode* str ) { return addDataUString( buffer, str ); } static const bool allowOStringConcat = false; static const bool allowOUStringConcat = true; }; |