diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-09-08 09:48:17 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-09-16 23:02:09 +0200 |
commit | e6dfaf9f44f9939abc338c83b3024108431d0f69 (patch) | |
tree | 2e220510dc589fa4ce9b205696b9d0b58d38b60a /extensions | |
parent | eb55bc5eae82873492cfd7577fb553b1c5abff6b (diff) |
Turn OUStringLiteral into a consteval'ed, static-refcound rtl_uString
...from which an OUString can cheaply be instantiated. This is the OUString
equivalent of 4b9e440c51be3e40326bc90c33ae69885bfb51e4 "Turn OStringLiteral into
a consteval'ed, static-refcound rtl_String". Most remarks about that commit
apply here too (this commit is just substantially bigger and a bit more
complicated because there were so much more uses of OUStringLiteral than of
OStringLiteral):
The one downside is that OUStringLiteral now needs to be a template abstracting
over the string length. But any uses for which that is a problem (e.g., as the
element type of a container that would no longer be homogeneous, or in the
signature of a function that shall not be turned into a template for one reason
or another) can be replaced with std::u16string_view, without loss of efficiency
compared to the original OUStringLiteral, and without loss of expressivity.
The new OUStringLiteral ctor code would probably not be very efficient if it
were ever executed at runtime, but it is intended to be only executed at compile
time. Where available, C++20 "consteval" is used to statically ensure that.
The intended use of the new OUStringLiteral is in all cases where an
object that shall itself not be an OUString (e.g., because it shall be a
global static variable for which the OUString ctor/dtor would be detrimental at
library load/unload) must be converted to an OUString instance in at least one
place. Other string literal abstractions could use std::u16string_view (or just
plain char16_t const[N]), but interestingly OUStringLiteral might be more
efficient than constexpr std::u16string_view even for such cases, as it should
not need any relocations at library load time. For now, no existing uses of
OUStringLiteral have been changed to some other abstraction (unless technically
necessary as discussed above), and no additional places that would benefit from
OUStringLiteral have been changed to use it.
Global constexpr OUStringLiteral variables defined in an included file would be
somewhat suboptimal, as each translation unit that uses them would create its
own, unshared instance. The envisioned solution is to turn them into static
data members of some class (and there may be a loplugin coming to find and fix
affected places). Another approach that has been taken here in a few cases
where such variables were only used in one .cxx anyway is to move their
definitions from the .hxx into that one .cxx (in turn causing some files to
become empty and get removed completely)---which also silenced some GCC
-Werror=unused-variable if a variable from a .hxx was not used in some .cxx
including it.
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.
In a similar vein, comparison operators between OUString and std::u16string_view
have been added to the existing plethora of comparison operator overloads. It
would be nice to eventually consolidate them, esp. with the overloads taking
OUStringLiteral and/or char16_t const[N] string literals, but that appears
tricky to get right without introducing new ambiguities. Also, a handful of
places across the code base use comparisons between OUString and OUStringNumber,
which are now ambiguous (converting the OUStringNumber to either OUString or
std::u16string_view). For simplicity, those few places have manually been fixed
for now by adding explicit conversion to std::u16string_view.
Also some compilerplugins code needed to be adapted, and some of the
compilerplugins/test cases have become irrelevant (and have been removed), as
the tested code would no longer compile in the first place.
sal/qa/rtl/strings/test_oustring_concat.cxx documents a workaround for GCC bug
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96878> "Failed class template
argument deduction in unevaluated, parenthesized context". That place, as well
as uses of OUStringLiteral in extensions/source/abpilot/fieldmappingimpl.cxx and
i18npool/source/localedata/localedata.cxx, which have been replaced with
OUString::Concat (and which is arguably a better choice, anyway), also caused
failures with at least Clang 5.0.2 (but would not have caused failures with at
least recent Clang 12 trunk, so appear to be bugs in Clang that have meanwhile
been fixed).
Change-Id: I34174462a28f2000cfeb2d219ffd533a767920b8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102222
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/IwyuFilter_extensions.yaml | 3 | ||||
-rw-r--r-- | extensions/source/abpilot/fieldmappingimpl.cxx | 2 | ||||
-rw-r--r-- | extensions/source/bibliography/bibconfig.cxx | 2 | ||||
-rw-r--r-- | extensions/source/bibliography/bibmod.cxx | 7 | ||||
-rw-r--r-- | extensions/source/bibliography/bibprop.hxx | 30 | ||||
-rw-r--r-- | extensions/source/bibliography/datman.cxx | 6 | ||||
-rw-r--r-- | extensions/source/bibliography/toolbar.cxx | 10 | ||||
-rw-r--r-- | extensions/source/logging/loggerconfig.cxx | 15 | ||||
-rw-r--r-- | extensions/source/propctrlr/formcomponenthandler.cxx | 7 | ||||
-rw-r--r-- | extensions/source/propctrlr/selectlabeldialog.cxx | 6 |
10 files changed, 31 insertions, 57 deletions
diff --git a/extensions/IwyuFilter_extensions.yaml b/extensions/IwyuFilter_extensions.yaml index ad9759f07188..043e83076d66 100644 --- a/extensions/IwyuFilter_extensions.yaml +++ b/extensions/IwyuFilter_extensions.yaml @@ -10,9 +10,6 @@ excludelist: extensions/source/abpilot/unodialogabp.cxx: # Needed for direct member access - com/sun/star/awt/XWindow.hpp - extensions/source/bibliography/bibmod.cxx: - # Needed for STATIC_USTRING macro + extern string magic to work at linking time - - bibprop.hxx extensions/source/bibliography/framectr.cxx: # Don't propose hxx -> h change in URE libs - cppuhelper/interfacecontainer.hxx diff --git a/extensions/source/abpilot/fieldmappingimpl.cxx b/extensions/source/abpilot/fieldmappingimpl.cxx index 6284aa977ff5..df003f36d07f 100644 --- a/extensions/source/abpilot/fieldmappingimpl.cxx +++ b/extensions/source/abpilot/fieldmappingimpl.cxx @@ -153,7 +153,7 @@ namespace abp // access the configuration information which the driver uses for determining its column names OUString sDriverAliasesNodeName( - OUStringLiteral(sDriverSettingsNodeName) + OUString::Concat(sDriverSettingsNodeName) + "/ColumnAliases"); // create a config node for this diff --git a/extensions/source/bibliography/bibconfig.cxx b/extensions/source/bibliography/bibconfig.cxx index c6531cfda7e2..ee271f4cc898 100644 --- a/extensions/source/bibliography/bibconfig.cxx +++ b/extensions/source/bibliography/bibconfig.cxx @@ -33,7 +33,7 @@ using namespace ::com::sun::star::lang; using namespace ::com::sun::star::sdb; -const char16_t cDataSourceHistory[] = u"DataSourceHistory"; +constexpr char16_t cDataSourceHistory[] = u"DataSourceHistory"; Sequence<OUString> const & BibConfig::GetPropertyNames() { diff --git a/extensions/source/bibliography/bibmod.cxx b/extensions/source/bibliography/bibmod.cxx index 3ae8a473a9f8..1a4f6cca47d2 100644 --- a/extensions/source/bibliography/bibmod.cxx +++ b/extensions/source/bibliography/bibmod.cxx @@ -20,7 +20,6 @@ #include <unotools/resmgr.hxx> #include "bibmod.hxx" -#include "bibprop.hxx" #include "bibresid.hxx" #include "datman.hxx" #include "bibconfig.hxx" @@ -87,10 +86,4 @@ BibConfig* BibModul::GetConfig() return pBibConfig; } - -// PropertyNames -const OUStringLiteral FM_PROP_LABEL = u"Label"; -const OUStringLiteral FM_PROP_CONTROLSOURCE = u"DataField"; -const OUStringLiteral FM_PROP_NAME = u"Name"; - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/extensions/source/bibliography/bibprop.hxx b/extensions/source/bibliography/bibprop.hxx deleted file mode 100644 index 5e670bcc6fa9..000000000000 --- a/extensions/source/bibliography/bibprop.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_BIBPROP_HXX -#define INCLUDED_EXTENSIONS_SOURCE_BIBLIOGRAPHY_BIBPROP_HXX - -#include <rtl/ustring.hxx> - -extern const OUStringLiteral FM_PROP_LABEL; -extern const OUStringLiteral FM_PROP_NAME; -extern const OUStringLiteral FM_PROP_CONTROLSOURCE; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/extensions/source/bibliography/datman.cxx b/extensions/source/bibliography/datman.cxx index d782b01f9f20..47754921b3e9 100644 --- a/extensions/source/bibliography/datman.cxx +++ b/extensions/source/bibliography/datman.cxx @@ -51,7 +51,6 @@ #include "bibresid.hxx" #include "bibmod.hxx" #include "bibview.hxx" -#include "bibprop.hxx" #include "toolbar.hxx" #include "bibconfig.hxx" #include "bibbeam.hxx" @@ -72,6 +71,11 @@ using namespace ::com::sun::star::form; using namespace ::com::sun::star::frame; using namespace ::com::sun::star::lang; +// PropertyNames +constexpr OUStringLiteral FM_PROP_LABEL = u"Label"; +constexpr OUStringLiteral FM_PROP_CONTROLSOURCE = u"DataField"; +constexpr OUStringLiteral FM_PROP_NAME = u"Name"; + static Reference< XConnection > getConnection(const OUString& _rURL) { // first get the sdb::DataSource corresponding to the url diff --git a/extensions/source/bibliography/toolbar.cxx b/extensions/source/bibliography/toolbar.cxx index 898d59337399..12f6cb5cb2df 100644 --- a/extensions/source/bibliography/toolbar.cxx +++ b/extensions/source/bibliography/toolbar.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <comphelper/processfactory.hxx> #include <com/sun/star/frame/XDispatch.hpp> #include <com/sun/star/frame/XDispatchProvider.hpp> @@ -597,9 +601,9 @@ void BibToolBar::RebuildToolbar() void BibToolBar::ApplyImageList() { - SetItemImage(nTBC_BT_AUTOFILTER, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? OUStringLiteral(u"" RID_EXTBMP_AUTOFILTER_SC) : OUStringLiteral(u"" RID_EXTBMP_AUTOFILTER_LC))); - SetItemImage(nTBC_BT_FILTERCRIT, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? OUStringLiteral(u"" RID_EXTBMP_FILTERCRIT_SC) : OUStringLiteral(u"" RID_EXTBMP_FILTERCRIT_LC))); - SetItemImage(nTBC_BT_REMOVEFILTER, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? OUStringLiteral(u"" RID_EXTBMP_REMOVE_FILTER_SORT_SC) : OUStringLiteral(u"" RID_EXTBMP_REMOVE_FILTER_SORT_LC))); + SetItemImage(nTBC_BT_AUTOFILTER, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? std::u16string_view(u"" RID_EXTBMP_AUTOFILTER_SC) : std::u16string_view(u"" RID_EXTBMP_AUTOFILTER_LC))); + SetItemImage(nTBC_BT_FILTERCRIT, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? std::u16string_view(u"" RID_EXTBMP_FILTERCRIT_SC) : std::u16string_view(u"" RID_EXTBMP_FILTERCRIT_LC))); + SetItemImage(nTBC_BT_REMOVEFILTER, Image(StockImage::Yes, nSymbolsSize == SFX_SYMBOLS_SIZE_SMALL ? std::u16string_view(u"" RID_EXTBMP_REMOVE_FILTER_SORT_SC) : std::u16string_view(u"" RID_EXTBMP_REMOVE_FILTER_SORT_LC))); AdjustToolBox(); } diff --git a/extensions/source/logging/loggerconfig.cxx b/extensions/source/logging/loggerconfig.cxx index a78c1385363d..4fd183099544 100644 --- a/extensions/source/logging/loggerconfig.cxx +++ b/extensions/source/logging/loggerconfig.cxx @@ -20,6 +20,7 @@ #include "loggerconfig.hxx" #include <stdio.h> +#include <string_view> #include <com/sun/star/configuration/theDefaultProvider.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> @@ -75,7 +76,7 @@ namespace logging { struct Variable { - OUStringLiteral pVariablePattern; + std::u16string_view pVariablePattern; OUString sVariableValue; }; @@ -115,11 +116,11 @@ namespace logging Variable const aVariables[] = { - {OUStringLiteral(u"$(loggername)"), sLoggerName}, - {OUStringLiteral(u"$(date)"), sDate}, - {OUStringLiteral(u"$(time)"), sTime}, - {OUStringLiteral(u"$(datetime)"), sDateTime}, - {OUStringLiteral(u"$(pid)"), aPID} + {std::u16string_view(u"$(loggername)"), sLoggerName}, + {std::u16string_view(u"$(date)"), sDate}, + {std::u16string_view(u"$(time)"), sTime}, + {std::u16string_view(u"$(datetime)"), sDateTime}, + {std::u16string_view(u"$(pid)"), aPID} }; for (Variable const & aVariable : aVariables) @@ -127,7 +128,7 @@ namespace logging sal_Int32 nVariableIndex = _inout_rFileURL.indexOf( aVariable.pVariablePattern ); if (nVariableIndex >= 0) { - _inout_rFileURL = _inout_rFileURL.replaceAt( nVariableIndex, aVariable.pVariablePattern.size, aVariable.sVariableValue ); + _inout_rFileURL = _inout_rFileURL.replaceAt( nVariableIndex, aVariable.pVariablePattern.size(), aVariable.sVariableValue ); } } } diff --git a/extensions/source/propctrlr/formcomponenthandler.cxx b/extensions/source/propctrlr/formcomponenthandler.cxx index c8a3cde773ba..fd71ce028da8 100644 --- a/extensions/source/propctrlr/formcomponenthandler.cxx +++ b/extensions/source/propctrlr/formcomponenthandler.cxx @@ -104,6 +104,7 @@ #include <limits> #include <memory> +#include <string_view> namespace pcr { @@ -996,8 +997,8 @@ namespace pcr aDescriptor.Control = pControl; aDescriptor.PrimaryButtonId = PROPERTY_ID_TARGET_URL == nPropId - ? OUStringLiteral(u"" UID_PROP_DLG_ATTR_TARGET_URL) - : OUStringLiteral(u"" UID_PROP_DLG_IMAGE_URL); + ? std::u16string_view(u"" UID_PROP_DLG_ATTR_TARGET_URL) + : std::u16string_view(u"" UID_PROP_DLG_IMAGE_URL); break; } @@ -1376,7 +1377,7 @@ namespace pcr aDescriptor.HasSecondaryButton = true; bool bIsDataProperty = ( nPropertyUIFlags & PROP_FLAG_DATA_PROPERTY ) != 0; - aDescriptor.Category = bIsDataProperty ? OUStringLiteral(u"Data") : OUStringLiteral(u"General"); + aDescriptor.Category = bIsDataProperty ? std::u16string_view(u"Data") : std::u16string_view(u"General"); return aDescriptor; } diff --git a/extensions/source/propctrlr/selectlabeldialog.cxx b/extensions/source/propctrlr/selectlabeldialog.cxx index 05b669aa0d7b..9cefcb72b273 100644 --- a/extensions/source/propctrlr/selectlabeldialog.cxx +++ b/extensions/source/propctrlr/selectlabeldialog.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include "selectlabeldialog.hxx" #include <strings.hrc> #include <bitmaps.hlst> @@ -91,7 +95,7 @@ namespace pcr // check which service the allowed components must support sal_Int16 nClassId = 0; try { nClassId = ::comphelper::getINT16(m_xControlModel->getPropertyValue(PROPERTY_CLASSID)); } catch(...) { } - m_sRequiredService = (FormComponentType::RADIOBUTTON == nClassId) ? OUStringLiteral(u"" SERVICE_COMPONENT_GROUPBOX) : OUStringLiteral(u"" SERVICE_COMPONENT_FIXEDTEXT); + m_sRequiredService = (FormComponentType::RADIOBUTTON == nClassId) ? std::u16string_view(u"" SERVICE_COMPONENT_GROUPBOX) : std::u16string_view(u"" SERVICE_COMPONENT_FIXEDTEXT); m_aRequiredControlImage = (FormComponentType::RADIOBUTTON == nClassId) ? OUStringLiteral(u"" RID_EXTBMP_GROUPBOX) : OUStringLiteral(u"" RID_EXTBMP_FIXEDTEXT); // calc the currently set label control (so InsertEntries can calc m_xInitialSelection) |