diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-08-27 11:40:59 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-08-28 08:07:09 +0200 |
commit | 33ecd0d5c4fff9511a8436513936a3f7044a775a (patch) | |
tree | c25809adda140ff89d9f2a2b6dfadba17e188fb0 /compilerplugins | |
parent | 554834484a3323f73b5aeace246bcd9635368967 (diff) |
Change OUStringLiteral from char[] to char16_t[]
This is a prerequisite for making conversion from OUStringLiteral to OUString
more efficient at least for C++20 (by replacing its internals with a constexpr-
generated sal_uString-compatible layout with a SAL_STRING_STATIC_FLAG refCount,
conditionally for C++20 for now).
For a configure-wise bare-bones build on Linux, size reported by `du -bs
instdir` grew by 118792 bytes from 1155636636 to 1155755428.
In most places just a u"..." string literal prefix had to be added. In some
places
char const a[] = "...";
variables have been changed to char16_t, and a few places required even further
changes to code (which prompted the addition of include/o3tl/string_view.hxx
helper function o3tl::equalsIgnoreAsciiCase and the additional
OUString::createFromAscii overload).
For all uses of macros expanding to string literals, the relevant uses have been
rewritten as
u"" MACRO
instead of changing the macro definitions. It should be possible to change at
least some of those macro definitions (and drop the u"" from their call sites)
in follow-up commits.
Change-Id: Iec4ef1a057d412d22443312d40c6a8a290dc6144
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101483
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/stringstatic.cxx | 4 | ||||
-rw-r--r-- | compilerplugins/clang/test/conditionalstring.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/test/elidestringvar.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/test/staticvar.cxx | 2 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringadd.cxx | 3 | ||||
-rw-r--r-- | compilerplugins/clang/test/stringconcatliterals.cxx | 14 |
6 files changed, 15 insertions, 12 deletions
diff --git a/compilerplugins/clang/stringstatic.cxx b/compilerplugins/clang/stringstatic.cxx index 61dfb584ddf5..c5753445fc34 100644 --- a/compilerplugins/clang/stringstatic.cxx +++ b/compilerplugins/clang/stringstatic.cxx @@ -17,8 +17,8 @@ /** Look for static O*String and O*String[], they can be more efficiently declared as: - static const OUStringLiteral our_aLBEntryMap[] = {" ", ", "}; - static const OUStringLiteral sName("name"); + static const OUStringLiteral our_aLBEntryMap[] = {u" ", u", "}; + static const OUStringLiteral sName(u"name"); which is more efficient at startup time. */ diff --git a/compilerplugins/clang/test/conditionalstring.cxx b/compilerplugins/clang/test/conditionalstring.cxx index e10b02519f8e..f38bc1d2436f 100644 --- a/compilerplugins/clang/test/conditionalstring.cxx +++ b/compilerplugins/clang/test/conditionalstring.cxx @@ -18,7 +18,7 @@ void f(OUString s, bool b) s += (b ? OUString("a") : throw 0); // expected-error@+2 {{replace 2nd operand of conditional expression with `rtl::OUStringLiteral` [loplugin:conditionalstring]}} // expected-note@+1 {{conditional expression is here [loplugin:conditionalstring]}} - s += (b ? OUString("a") : OUStringLiteral("b")); + s += (b ? OUString("a") : OUStringLiteral(u"b")); // expected-error@+1 {{replace both 2nd and 3rd operands of conditional expression with `rtl::OUStringLiteral` [loplugin:conditionalstring]}} b = (b ? ("x") : (OUString(("y")))) == s; // expected-error@+1 {{replace both 2nd and 3rd operands of conditional expression with `rtl::OUStringLiteral` [loplugin:conditionalstring]}} diff --git a/compilerplugins/clang/test/elidestringvar.cxx b/compilerplugins/clang/test/elidestringvar.cxx index e7a5f40a8eae..bc0de05c999e 100644 --- a/compilerplugins/clang/test/elidestringvar.cxx +++ b/compilerplugins/clang/test/elidestringvar.cxx @@ -19,7 +19,7 @@ OUString f(sal_Unicode c, int n) // expected-note@+1 {{literal OUString variable defined here [loplugin:elidestringvar]}} OUString s3(u'a'); // expected-note@+1 {{literal OUString variable defined here [loplugin:elidestringvar]}} - OUString s4 = OUStringLiteral("a"); + OUString s4 = OUStringLiteral(u"a"); switch (n) { case 1: diff --git a/compilerplugins/clang/test/staticvar.cxx b/compilerplugins/clang/test/staticvar.cxx index 3ae040a2e5a0..f527df6a521a 100644 --- a/compilerplugins/clang/test/staticvar.cxx +++ b/compilerplugins/clang/test/staticvar.cxx @@ -58,7 +58,7 @@ struct S4 S4 const& f4() { static const S4 s1[] = { - { OUStringLiteral("/DocColor"), false }, + { OUStringLiteral(u"/DocColor"), false }, }; return s1[0]; } diff --git a/compilerplugins/clang/test/stringadd.cxx b/compilerplugins/clang/test/stringadd.cxx index 748ee35cfe61..0879805d3449 100644 --- a/compilerplugins/clang/test/stringadd.cxx +++ b/compilerplugins/clang/test/stringadd.cxx @@ -18,6 +18,7 @@ namespace test1 { static const char XXX1[] = "xxx"; +static const char16_t XXX1u[] = u"xxx"; static const char XXX2[] = "xxx"; void f1(OUString s1, int i, OString o) { @@ -36,7 +37,7 @@ void f1(OUString s1, int i, OString o) // expected-error@+1 {{simplify by merging with the preceding assignment [loplugin:stringadd]}} s2 += XXX1; // expected-error@+1 {{simplify by merging with the preceding assignment [loplugin:stringadd]}} - s2 += OUStringLiteral(XXX1) + XXX2; + s2 += OUStringLiteral(XXX1u) + XXX2; // expected-error@+1 {{simplify by merging with the preceding assignment [loplugin:stringadd]}} s2 += OStringToOUString(o, RTL_TEXTENCODING_UTF8); diff --git a/compilerplugins/clang/test/stringconcatliterals.cxx b/compilerplugins/clang/test/stringconcatliterals.cxx index e2d5a8ce20e3..76b82797f77e 100644 --- a/compilerplugins/clang/test/stringconcatliterals.cxx +++ b/compilerplugins/clang/test/stringconcatliterals.cxx @@ -15,10 +15,12 @@ #include <rtl/ustring.hxx> #define FOO "foo" +#define FOOu u"foo" void f(std::ostream& s1) { static char const foo[] = "foo"; + static char16_t const foou[] = u"foo"; s1 << "foo" << "foo"; // expected-error@-1 {{replace '<<' between string literals with juxtaposition}} @@ -35,9 +37,9 @@ void f(std::ostream& s1) s1 << "foo" << OUString(FOO); // expected-error@-1 {{replace '<<' between string literals with juxtaposition}} s1 << "foo" << OUString(foo); - s1 << "foo" << OUStringLiteral("foo"); //TODO: warn too, OUStringLiteral wrapped in OUString - s1 << "foo" << OUStringLiteral(FOO); //TODO: warn too, OUStringLiteral wrapped in OUString - s1 << "foo" << OUStringLiteral(foo); + s1 << "foo" << OUStringLiteral(u"foo"); //TODO: warn too, OUStringLiteral wrapped in OUString + s1 << "foo" << OUStringLiteral(FOOu); //TODO: warn too, OUStringLiteral wrapped in OUString + s1 << "foo" << OUStringLiteral(foou); OString s2; s2 = "foo" + OString("foo"); // expected-error@-1 {{replace '+' between string literals with juxtaposition}} @@ -55,11 +57,11 @@ void f(std::ostream& s1) s3 = "foo" + OUString(FOO); // expected-error@-1 {{replace '+' between string literals with juxtaposition}} s3 = "foo" + OUString(foo); - s3 = "foo" + OUStringLiteral("foo"); + s3 = "foo" + OUStringLiteral(u"foo"); // expected-error@-1 {{replace '+' between string literals with juxtaposition}} - s3 = "foo" + OUStringLiteral(FOO); + s3 = "foo" + OUStringLiteral(FOOu); // expected-error@-1 {{replace '+' between string literals with juxtaposition}} - s3 = "foo" + OUStringLiteral(foo); + s3 = "foo" + OUStringLiteral(foou); } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |