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 /xmloff | |
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 'xmloff')
-rw-r--r-- | xmloff/source/core/XMLEmbeddedObjectImportContext.cxx | 22 | ||||
-rw-r--r-- | xmloff/source/core/xmlimp.cxx | 2 | ||||
-rw-r--r-- | xmloff/source/draw/animimp.cxx | 8 | ||||
-rw-r--r-- | xmloff/source/draw/shapeimport.cxx | 9 | ||||
-rw-r--r-- | xmloff/source/forms/elementexport.cxx | 3 | ||||
-rw-r--r-- | xmloff/source/text/txtfldi.cxx | 4 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 21 | ||||
-rw-r--r-- | xmloff/source/text/txtvfldi.cxx | 2 |
8 files changed, 29 insertions, 42 deletions
diff --git a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx index 2293e726399d..3255e2e6fdbf 100644 --- a/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx +++ b/xmloff/source/core/XMLEmbeddedObjectImportContext.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <com/sun/star/document/XImporter.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/util/XModifiable2.hpp> @@ -169,7 +173,7 @@ XMLEmbeddedObjectImportContext::XMLEmbeddedObjectImportContext( } OUString sClass; - static OUStringLiteral const prefixes[] = { + static std::u16string_view const prefixes[] = { u"application/vnd.oasis.openoffice.", u"application/x-vnd.oasis.openoffice.", u"application/vnd.oasis.opendocument.", @@ -184,15 +188,15 @@ XMLEmbeddedObjectImportContext::XMLEmbeddedObjectImportContext( if( !sClass.isEmpty() ) { - static struct { XMLTokenEnum eClass; OUStringLiteral sFilterService; + static struct { XMLTokenEnum eClass; std::u16string_view sFilterService; } const aServiceMap[] = { - { XML_TEXT, OUStringLiteral(u"" XML_IMPORT_FILTER_WRITER) }, - { XML_ONLINE_TEXT, OUStringLiteral(u"" XML_IMPORT_FILTER_WRITER) }, - { XML_SPREADSHEET, OUStringLiteral(u"" XML_IMPORT_FILTER_CALC) }, - { XML_DRAWING, OUStringLiteral(u"" XML_IMPORT_FILTER_DRAW) }, - { XML_GRAPHICS, OUStringLiteral(u"" XML_IMPORT_FILTER_DRAW) }, - { XML_PRESENTATION, OUStringLiteral(u"" XML_IMPORT_FILTER_IMPRESS) }, - { XML_CHART, OUStringLiteral(u"" XML_IMPORT_FILTER_CHART) }}; + { XML_TEXT, std::u16string_view(u"" XML_IMPORT_FILTER_WRITER) }, + { XML_ONLINE_TEXT, std::u16string_view(u"" XML_IMPORT_FILTER_WRITER) }, + { XML_SPREADSHEET, std::u16string_view(u"" XML_IMPORT_FILTER_CALC) }, + { XML_DRAWING, std::u16string_view(u"" XML_IMPORT_FILTER_DRAW) }, + { XML_GRAPHICS, std::u16string_view(u"" XML_IMPORT_FILTER_DRAW) }, + { XML_PRESENTATION, std::u16string_view(u"" XML_IMPORT_FILTER_IMPRESS) }, + { XML_CHART, std::u16string_view(u"" XML_IMPORT_FILTER_CHART) }}; for (auto const & entry: aServiceMap) { if( IsXMLToken( sClass, entry.eClass ) ) diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index 0a289c6e9fc5..2aeda90fc229 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -85,8 +85,6 @@ using namespace ::xmloff::token; rtl::Reference< FastTokenHandler > SvXMLImport::xTokenHandler( new FastTokenHandler() ); std::unordered_map< sal_Int32, std::pair< OUString, OUString > > SvXMLImport::aNamespaceMap; std::unordered_map< OUString, OUString > SvXMLImport::aNamespaceURIPrefixMap; -const OUStringLiteral SvXMLImport::aDefaultNamespace = u""; -const OUStringLiteral SvXMLImport::aNamespaceSeparator = u":"; bool SvXMLImport::bIsNSMapsInitialized = false; namespace { diff --git a/xmloff/source/draw/animimp.cxx b/xmloff/source/draw/animimp.cxx index c0c471f92f50..6dfb4aed4ccd 100644 --- a/xmloff/source/draw/animimp.cxx +++ b/xmloff/source/draw/animimp.cxx @@ -17,6 +17,10 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include <string_view> + #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/presentation/AnimationEffect.hpp> @@ -321,12 +325,12 @@ namespace constexpr OUStringLiteral gsDimColor = u"DimColor"; constexpr OUStringLiteral gsDimHide = u"DimHide"; constexpr OUStringLiteral gsDimPrev = u"DimPrevious"; - constexpr OUStringLiteral gsEffect = u"Effect"; + constexpr std::u16string_view gsEffect = u"Effect"; constexpr OUStringLiteral gsPlayFull = u"PlayFull"; constexpr OUStringLiteral gsSound = u"Sound"; constexpr OUStringLiteral gsSoundOn = u"SoundOn"; constexpr OUStringLiteral gsSpeed = u"Speed"; - constexpr OUStringLiteral gsTextEffect = u"TextEffect"; + constexpr std::u16string_view gsTextEffect = u"TextEffect"; constexpr OUStringLiteral gsPresShapeService = u"com.sun.star.presentation.Shape"; constexpr OUStringLiteral gsAnimPath = u"AnimationPath"; constexpr OUStringLiteral gsIsAnimation = u"IsAnimation"; diff --git a/xmloff/source/draw/shapeimport.cxx b/xmloff/source/draw/shapeimport.cxx index 8797425eb8c7..47309a3ab28f 100644 --- a/xmloff/source/draw/shapeimport.cxx +++ b/xmloff/source/draw/shapeimport.cxx @@ -45,6 +45,7 @@ #include "ximplink.hxx" #include <map> +#include <string_view> #include <vector> namespace { @@ -110,10 +111,10 @@ struct XMLShapeImportHelperImpl bool mbIsPresentationShapesSupported; }; -const OUStringLiteral gsStartShape(u"StartShape"); -const OUStringLiteral gsEndShape(u"EndShape"); -const OUStringLiteral gsStartGluePointIndex(u"StartGluePointIndex"); -const OUStringLiteral gsEndGluePointIndex(u"EndGluePointIndex"); +const std::u16string_view gsStartShape(u"StartShape"); +const std::u16string_view gsEndShape(u"EndShape"); +const std::u16string_view gsStartGluePointIndex(u"StartGluePointIndex"); +const std::u16string_view gsEndGluePointIndex(u"EndGluePointIndex"); XMLShapeImportHelper::XMLShapeImportHelper( SvXMLImport& rImporter, diff --git a/xmloff/source/forms/elementexport.cxx b/xmloff/source/forms/elementexport.cxx index a60d70437d9e..1006fc19a152 100644 --- a/xmloff/source/forms/elementexport.cxx +++ b/xmloff/source/forms/elementexport.cxx @@ -62,6 +62,7 @@ #include <sal/log.hxx> #include <algorithm> +#include <string_view> namespace xmloff { @@ -1122,7 +1123,7 @@ namespace xmloff { // attribute flags SCAFlags::GroupName }; - static const OUStringLiteral pStringPropertyNames[] = + static const std::u16string_view pStringPropertyNames[] = { // property names u"" PROPERTY_GROUP_NAME }; diff --git a/xmloff/source/text/txtfldi.cxx b/xmloff/source/text/txtfldi.cxx index 31a331f20504..958ebd6b4a92 100644 --- a/xmloff/source/text/txtfldi.cxx +++ b/xmloff/source/text/txtfldi.cxx @@ -81,8 +81,8 @@ using namespace ::xmloff::token; // service prefix and service names -const char16_t sAPI_textfield_prefix[] = u"com.sun.star.text.TextField."; -const char16_t sAPI_fieldmaster_prefix[] = u"com.sun.star.text.FieldMaster."; +constexpr char16_t sAPI_textfield_prefix[] = u"com.sun.star.text.TextField."; +constexpr char16_t sAPI_fieldmaster_prefix[] = u"com.sun.star.text.FieldMaster."; const char sAPI_presentation_prefix[] = "com.sun.star.presentation.TextField."; const char sAPI_date_time[] = "DateTime"; diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 70d0d6ef11c1..09e923957221 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -128,20 +128,12 @@ using namespace ::xmloff::token; // Implement Title/Description Elements UI (#i73249#) const OUStringLiteral gsTitle(u"Title"); const OUStringLiteral gsDescription(u"Description"); -const OUStringLiteral XMLTextParagraphExport::gsAnchorCharStyleName(u"AnchorCharStyleName"); const OUStringLiteral gsAnchorPageNo(u"AnchorPageNo"); const OUStringLiteral gsAnchorType(u"AnchorType"); -const OUStringLiteral XMLTextParagraphExport::gsBeginNotice(u"BeginNotice"); const OUStringLiteral gsBookmark(u"Bookmark"); -const OUStringLiteral XMLTextParagraphExport::gsCategory(u"Category"); const OUStringLiteral gsChainNextName(u"ChainNextName"); -const OUStringLiteral XMLTextParagraphExport::gsCharStyleName(u"CharStyleName"); -const OUStringLiteral XMLTextParagraphExport::gsCharStyleNames(u"CharStyleNames"); const OUStringLiteral gsContourPolyPolygon(u"ContourPolyPolygon"); const OUStringLiteral gsDocumentIndexMark(u"DocumentIndexMark"); -const OUStringLiteral XMLTextParagraphExport::gsEndNotice(u"EndNotice"); -const OUStringLiteral XMLTextParagraphExport::gsFootnote(u"Footnote"); -const OUStringLiteral XMLTextParagraphExport::gsFootnoteCounting(u"FootnoteCounting"); const OUStringLiteral gsFrame(u"Frame"); const OUStringLiteral gsGraphicFilter(u"GraphicFilter"); const OUStringLiteral gsGraphicRotation(u"GraphicRotation"); @@ -158,16 +150,9 @@ const OUStringLiteral gsIsStart(u"IsStart"); const OUStringLiteral gsIsSyncHeightToWidth(u"IsSyncHeightToWidth"); const OUStringLiteral gsIsSyncWidthToHeight(u"IsSyncWidthToHeight"); const OUStringLiteral gsNumberingRules(u"NumberingRules"); -const OUStringLiteral XMLTextParagraphExport::gsNumberingType(u"NumberingType"); -const OUStringLiteral XMLTextParagraphExport::gsPageDescName(u"PageDescName"); -const OUStringLiteral XMLTextParagraphExport::gsPageStyleName(u"PageStyleName"); const OUStringLiteral gsParaConditionalStyleName(u"ParaConditionalStyleName"); const OUStringLiteral gsParagraphService(u"com.sun.star.text.Paragraph"); -const OUStringLiteral XMLTextParagraphExport::gsParaStyleName(u"ParaStyleName"); -const OUStringLiteral XMLTextParagraphExport::gsPositionEndOfDoc(u"PositionEndOfDoc"); -const OUStringLiteral XMLTextParagraphExport::gsPrefix(u"Prefix"); const OUStringLiteral gsRedline(u"Redline"); -const OUStringLiteral XMLTextParagraphExport::gsReferenceId(u"ReferenceId"); const OUStringLiteral gsReferenceMark(u"ReferenceMark"); const OUStringLiteral gsRelativeHeight(u"RelativeHeight"); const OUStringLiteral gsRelativeWidth(u"RelativeWidth"); @@ -178,19 +163,15 @@ const OUStringLiteral gsServerMap(u"ServerMap"); const OUStringLiteral gsShapeService(u"com.sun.star.drawing.Shape"); const OUStringLiteral gsSizeType(u"SizeType"); const OUStringLiteral gsSoftPageBreak( u"SoftPageBreak" ); -const OUStringLiteral XMLTextParagraphExport::gsStartAt(u"StartAt"); -const OUStringLiteral XMLTextParagraphExport::gsSuffix(u"Suffix"); const OUStringLiteral gsTableService(u"com.sun.star.text.TextTable"); const OUStringLiteral gsText(u"Text"); const OUStringLiteral gsTextContentService(u"com.sun.star.text.TextContent"); const OUStringLiteral gsTextEmbeddedService(u"com.sun.star.text.TextEmbeddedObject"); -const OUStringLiteral XMLTextParagraphExport::gsTextEndnoteService(u"com.sun.star.text.Endnote"); const OUStringLiteral gsTextField(u"TextField"); const OUStringLiteral gsTextFieldService(u"com.sun.star.text.TextField"); const OUStringLiteral gsTextFrameService(u"com.sun.star.text.TextFrame"); const OUStringLiteral gsTextGraphicService(u"com.sun.star.text.TextGraphicObject"); const OUStringLiteral gsTextPortionType(u"TextPortionType"); -const OUStringLiteral XMLTextParagraphExport::gsTextSection(u"TextSection"); const OUStringLiteral gsUnvisitedCharStyleName(u"UnvisitedCharStyleName"); const OUStringLiteral gsVertOrient(u"VertOrient"); const OUStringLiteral gsVertOrientPosition(u"VertOrientPosition"); @@ -201,8 +182,6 @@ const OUStringLiteral gsTextFieldStart( u"TextFieldStart" ); const OUStringLiteral gsTextFieldEnd( u"TextFieldEnd" ); const OUStringLiteral gsTextFieldStartEnd( u"TextFieldStartEnd" ); -const OUStringLiteral XMLTextParagraphExport::gsFrameStyleName(u"FrameStyleName"); - namespace { class TextContentSet diff --git a/xmloff/source/text/txtvfldi.cxx b/xmloff/source/text/txtvfldi.cxx index 0cff25fedbb7..ed635d9a51c8 100644 --- a/xmloff/source/text/txtvfldi.cxx +++ b/xmloff/source/text/txtvfldi.cxx @@ -52,7 +52,7 @@ // service names -const char16_t sAPI_fieldmaster_prefix[] = u"com.sun.star.text.FieldMaster."; +constexpr char16_t sAPI_fieldmaster_prefix[] = u"com.sun.star.text.FieldMaster."; const char sAPI_get_expression[] = "GetExpression"; const char sAPI_set_expression[] = "SetExpression"; const char sAPI_user[] = "User"; |