diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2021-10-21 22:03:20 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2021-10-22 09:24:54 +0200 |
commit | df42cb6552b20372f62b5a361709670db80e4ed4 (patch) | |
tree | fe17971761e7ecf744ef170430c8452c77fa1053 /include | |
parent | e25b8056b25efea0094ef45c315471a7177e7210 (diff) |
Optimize assignment from OUStringLiteral to OUString
...by making the OUString's pData point to the OUStringLiteral, instead of
copying the contained characters. This is one of the improvements that had not
been done as part of e6dfaf9f44f9939abc338c83b3024108431d0f69 "Turn
OUStringLiteral into a consteval'ed, static-refcound rtl_uString": "To keep
individual commits reasonably manageable, some consumers of OUStringLiteral in
rtl/ustrbuf.hxx and rtl/ustring.hxx are left in a somewhat odd state for now,
where they don't take advantage of OUStringLiteral's equivalence to rtl_uString,
but just keep extracting its contents and copy it elsewhere. In follow-up
commits, those consumers should be changed appropriately, making them treat
OUStringLiteral like an rtl_uString or dropping the OUStringLiteral overload in
favor of an existing (and cheap to use now) OUString overload, etc." (Simply
dropping the OUStringLiteral overload was not possible in this case, though, as
that would have lead to ambiguities among the various OUString and
std::u16string_view overloads.)
The now-deleted OUStringLiteral rvalue reference overload means that some
existing assignments from ternary-operator OUStringLiteral<N> to OUString no
longer compile and had to be replaced with uses of std::u16string_view. Those
had not already been replaced in e6dfaf9f44f9939abc338c83b3024108431d0f69
because they happened to use OUStringLiteral instances of identical length N in
both arms of the ternary operator, so did not already start to fail to compile
back then.
Change-Id: I328e25b8324d045774e811d20a639f40d6a9a960
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124040
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/rtl/ustring.hxx | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index e092ff6370d7..9a893d3764af 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -584,13 +584,11 @@ public: /** @overload @since LibreOffice 5.4 */ template<std::size_t N> OUString & operator =(OUStringLiteral<N> const & literal) { - if (literal.getLength() == 0) { - rtl_uString_new(&pData); - } else { - rtl_uString_newFromStr_WithLength(&pData, literal.getStr(), literal.getLength()); - } + rtl_uString_release(pData); + pData = const_cast<rtl_uString *>(&literal.str); return *this; } + template<std::size_t N> OUString & operator =(OUStringLiteral<N> &&) = delete; template<typename T> OUString & operator =(OUStringNumber<T> && n) { |