diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2019-09-13 15:13:55 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2019-09-24 12:58:14 +0200 |
commit | 2f5f45921b05904a4be1ff633be09c62cb44ff08 (patch) | |
tree | ddd0cd5ef0349706f935d8360db88343347639a3 /compilerplugins | |
parent | a7d40f575463467698df76f041e558cb3bea7c85 (diff) |
support O(U)String::number() for fast string concatenation
When I did the fast string concatenation, I didn't add any support
for number(), which simply returned a O(U)String, and so it did
the extra allocation/deallocation, although that could be avoided.
In order to support this, number() now returns a special temporary
return type, similarly to O(U)StringConcat, which allows delaying
the concatenation the same way.
Also similarly, the change of the return type in some cases requires
explicit cast to the actual string type. Usage of OString::getStr()
is so extensive in the codebase that I actually added it to the helper
class, after that it's only relatively few cases.
Change-Id: Iba6e158010e1e458089698c426803052b6f46031
Reviewed-on: https://gerrit.libreoffice.org/78873
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/stringconcatauto.cxx | 4 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringconcatauto.cxx | 10 |
2 files changed, 14 insertions, 0 deletions
diff --git a/compilerplugins/clang/stringconcatauto.cxx b/compilerplugins/clang/stringconcatauto.cxx index 1437b7537323..7eac4965b3ee 100644 --- a/compilerplugins/clang/stringconcatauto.cxx +++ b/compilerplugins/clang/stringconcatauto.cxx @@ -87,6 +87,10 @@ bool StringConcatAuto::checkDecl( const DeclaratorDecl* decl, QualType type, con typeString = "OUString"; else if( tc.Struct("OStringConcat").Namespace("rtl").GlobalNamespace()) typeString = "OString"; + else if( tc.Struct("OUStringNumber").Namespace("rtl").GlobalNamespace()) + typeString = "OUString"; + else if( tc.Struct("OStringNumber").Namespace("rtl").GlobalNamespace()) + typeString = "OString"; else return true; report( DiagnosticsEngine::Warning, diff --git a/compilerplugins/clang/test/stringconcatauto.cxx b/compilerplugins/clang/test/stringconcatauto.cxx index 777da46e84a4..6c9a72c293b3 100644 --- a/compilerplugins/clang/test/stringconcatauto.cxx +++ b/compilerplugins/clang/test/stringconcatauto.cxx @@ -23,10 +23,14 @@ void foo() const auto str4 = "str4" + OString::number( 40 ); // expected-error-re@-1 {{creating a variable of type 'const rtl::OStringConcat<{{.*}}>' will make it reference temporaries}} // expected-note@-2 {{use OString instead}} + auto str5 = OUString::number( 50 ); + // expected-error-re@-1 {{creating a variable of type 'rtl::OUStringNumber<{{.*}}>' will make it reference temporaries}} + // expected-note@-2 {{use OUString instead}} (void) str1; (void) str2; (void) str3; (void) str4; + (void) str5; } struct A @@ -37,6 +41,12 @@ struct A { return "bar" + OString::number( 110 ); } + auto baz() + // expected-error-re@-1 {{returning a variable of type 'rtl::OStringNumber<{{.*}}>' will make it reference temporaries}} + // expected-note@-2 {{use OString instead}} + { + return OString::number( 120 ); + } }; template< typename T > |