summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-10-21 22:03:20 +0200
committerStephan Bergmann <sbergman@redhat.com>2021-10-22 09:24:54 +0200
commitdf42cb6552b20372f62b5a361709670db80e4ed4 (patch)
treefe17971761e7ecf744ef170430c8452c77fa1053
parente25b8056b25efea0094ef45c315471a7177e7210 (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>
-rw-r--r--basctl/source/basicide/bastype2.cxx2
-rw-r--r--dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx6
-rw-r--r--extensions/source/propctrlr/selectlabeldialog.cxx2
-rw-r--r--include/rtl/ustring.hxx8
-rw-r--r--reportdesign/source/ui/dlg/Navigator.cxx3
-rw-r--r--reportdesign/source/ui/misc/RptUndo.cxx5
-rw-r--r--sal/qa/rtl/strings/test_oustring_stringliterals.cxx3
-rw-r--r--sdext/source/pdfimport/tree/writertreevisiting.cxx2
-rw-r--r--sw/source/filter/html/htmlftn.cxx6
-rw-r--r--sw/source/filter/ww8/ww8par3.cxx3
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx3
-rw-r--r--writerfilter/source/dmapper/TablePropertiesHandler.cxx6
-rw-r--r--writerfilter/source/rtftok/rtfdispatchflag.cxx12
13 files changed, 39 insertions, 22 deletions
diff --git a/basctl/source/basicide/bastype2.cxx b/basctl/source/basicide/bastype2.cxx
index eed521ce3fd6..20350b41b9f2 100644
--- a/basctl/source/basicide/bastype2.cxx
+++ b/basctl/source/basicide/bastype2.cxx
@@ -245,7 +245,7 @@ void SbTreeListBox::ImpCreateLibEntries(const weld::TreeIter& rIter, const Scrip
if ( ( nMode & BrowseMode::Dialogs ) && !( nMode & BrowseMode::Modules ) )
sId = bLoaded ? std::u16string_view(u"" RID_BMP_DLGLIB) : std::u16string_view(u"" RID_BMP_DLGLIBNOTLOADED);
else
- sId = bLoaded ? OUStringLiteral(u"" RID_BMP_MODLIB) : OUStringLiteral(u"" RID_BMP_MODLIBNOTLOADED);
+ sId = bLoaded ? std::u16string_view(u"" RID_BMP_MODLIB) : std::u16string_view(u"" RID_BMP_MODLIBNOTLOADED);
std::unique_ptr<weld::TreeIter> xLibRootEntry(m_xControl->make_iterator(&rIter));
bool bLibRootEntry = FindEntry(aLibName, OBJ_TYPE_LIBRARY, *xLibRootEntry);
if (bLibRootEntry)
diff --git a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
index f1b4d9563962..235ed9bd1c41 100644
--- a/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
+++ b/dbaccess/source/ui/querydesign/SelectionBrowseBox.cxx
@@ -918,8 +918,10 @@ bool OSelectionBrowseBox::SaveModified()
case BROW_VIS_ROW:
{
bool bOldValue = m_pVisibleCell->GetBox().get_saved_state() != TRISTATE_FALSE;
- strOldCellContents = bOldValue ? OUStringLiteral(u"1") : OUStringLiteral(u"0");
- sNewValue = !bOldValue ? OUStringLiteral(u"1") : OUStringLiteral(u"0");
+ strOldCellContents
+ = bOldValue ? std::u16string_view(u"1") : std::u16string_view(u"0");
+ sNewValue
+ = !bOldValue ? std::u16string_view(u"1") : std::u16string_view(u"0");
}
if((m_bOrderByUnRelated || pEntry->GetOrderDir() == ORDER_NONE) &&
(m_bGroupByUnRelated || !pEntry->IsGroupBy()))
diff --git a/extensions/source/propctrlr/selectlabeldialog.cxx b/extensions/source/propctrlr/selectlabeldialog.cxx
index 216ff4967e13..9fbadf38cae4 100644
--- a/extensions/source/propctrlr/selectlabeldialog.cxx
+++ b/extensions/source/propctrlr/selectlabeldialog.cxx
@@ -96,7 +96,7 @@ namespace pcr
sal_Int16 nClassId = 0;
try { nClassId = ::comphelper::getINT16(m_xControlModel->getPropertyValue(PROPERTY_CLASSID)); } catch(...) { }
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);
+ m_aRequiredControlImage = (FormComponentType::RADIOBUTTON == nClassId) ? std::u16string_view(u"" RID_EXTBMP_GROUPBOX) : std::u16string_view(u"" RID_EXTBMP_FIXEDTEXT);
// calc the currently set label control (so InsertEntries can calc m_xInitialSelection)
Any aCurrentLabelControl( m_xControlModel->getPropertyValue(PROPERTY_CONTROLLABEL) );
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) {
diff --git a/reportdesign/source/ui/dlg/Navigator.cxx b/reportdesign/source/ui/dlg/Navigator.cxx
index af0e268957d5..edb4a7eefc15 100644
--- a/reportdesign/source/ui/dlg/Navigator.cxx
+++ b/reportdesign/source/ui/dlg/Navigator.cxx
@@ -46,6 +46,7 @@
#include <svx/svxids.hrc>
#include <memory>
+#include <string_view>
namespace rptui
{
@@ -60,7 +61,7 @@ static OUString lcl_getImageId(const uno::Reference< report::XReportComponent>&
if ( uno::Reference< report::XFixedText>(_xElement,uno::UNO_QUERY).is() )
sId = RID_SVXBMP_FM_FIXEDTEXT;
else if ( xFixedLine.is() )
- sId = xFixedLine->getOrientation() ? OUStringLiteral(u"" RID_SVXBMP_INSERT_VFIXEDLINE) : OUStringLiteral(u"" RID_SVXBMP_INSERT_HFIXEDLINE);
+ sId = xFixedLine->getOrientation() ? std::u16string_view(u"" RID_SVXBMP_INSERT_VFIXEDLINE) : std::u16string_view(u"" RID_SVXBMP_INSERT_HFIXEDLINE);
else if ( uno::Reference< report::XFormattedField>(_xElement,uno::UNO_QUERY).is() )
sId = RID_SVXBMP_FM_EDIT;
else if ( uno::Reference< report::XImageControl>(_xElement,uno::UNO_QUERY).is() )
diff --git a/reportdesign/source/ui/misc/RptUndo.cxx b/reportdesign/source/ui/misc/RptUndo.cxx
index d56171ec53c3..598669437063 100644
--- a/reportdesign/source/ui/misc/RptUndo.cxx
+++ b/reportdesign/source/ui/misc/RptUndo.cxx
@@ -35,6 +35,7 @@
#include <tools/diagnose_ex.h>
#include <functional>
+#include <string_view>
namespace rptui
{
@@ -284,7 +285,7 @@ void OGroupSectionUndo::implReInsert( )
{
uno::Sequence< beans::PropertyValue > aArgs(2);
- aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? OUStringLiteral(u"" PROPERTY_HEADERON) : OUStringLiteral(u"" PROPERTY_FOOTERON);
+ aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? std::u16string_view(u"" PROPERTY_HEADERON) : std::u16string_view(u"" PROPERTY_FOOTERON);
aArgs[0].Value <<= true;
aArgs[1].Name = PROPERTY_GROUP;
aArgs[1].Value <<= m_aGroupHelper.getGroup();
@@ -303,7 +304,7 @@ void OGroupSectionUndo::implReRemove( )
uno::Sequence< beans::PropertyValue > aArgs(2);
- aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? OUStringLiteral(u"" PROPERTY_HEADERON) : OUStringLiteral(u"" PROPERTY_FOOTERON);
+ aArgs[0].Name = SID_GROUPHEADER_WITHOUT_UNDO == m_nSlot? std::u16string_view(u"" PROPERTY_HEADERON) : std::u16string_view(u"" PROPERTY_FOOTERON);
aArgs[0].Value <<= false;
aArgs[1].Name = PROPERTY_GROUP;
aArgs[1].Value <<= m_aGroupHelper.getGroup();
diff --git a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
index 5bac89c5af4f..24867050fb7f 100644
--- a/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
+++ b/sal/qa/rtl/strings/test_oustring_stringliterals.cxx
@@ -188,7 +188,8 @@ void test::oustring::StringLiterals::checkOUStringLiteral()
static constexpr rtlunittest::OUStringLiteral s1lit(u"abc");
rtl::OUString s1(s1lit);
CPPUNIT_ASSERT_EQUAL(rtl::OUString("abc"), s1);
- s1 = rtlunittest::OUStringLiteral(u"de");
+ static constexpr rtlunittest::OUStringLiteral de(u"de");
+ s1 = de;
CPPUNIT_ASSERT_EQUAL(rtl::OUString("de"), s1);
s1 += rtlunittest::OUStringLiteral(u"fde");
CPPUNIT_ASSERT_EQUAL(rtl::OUString("defde"), s1);
diff --git a/sdext/source/pdfimport/tree/writertreevisiting.cxx b/sdext/source/pdfimport/tree/writertreevisiting.cxx
index f8211352f771..a3d66f33636a 100644
--- a/sdext/source/pdfimport/tree/writertreevisiting.cxx
+++ b/sdext/source/pdfimport/tree/writertreevisiting.cxx
@@ -128,7 +128,7 @@ void WriterXmlEmitter::fillFrameProps( DrawElement& rElem,
if (pParaElt)
{
rProps[ "text:anchor-type" ] = rElem.isCharacter
- ? OUStringLiteral(u"character") : OUStringLiteral(u"paragraph");
+ ? std::u16string_view(u"character") : std::u16string_view(u"paragraph");
}
else
{
diff --git a/sw/source/filter/html/htmlftn.cxx b/sw/source/filter/html/htmlftn.cxx
index a63a100ed5d9..cfb6f59671c3 100644
--- a/sw/source/filter/html/htmlftn.cxx
+++ b/sw/source/filter/html/htmlftn.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <string_view>
+
#include <osl/diagnose.h>
#include <svtools/htmlout.hxx>
#include <svtools/htmlkywd.hxx>
@@ -529,7 +533,7 @@ void SwHTMLWriter::OutFootEndNoteInfo()
int nParts = lcl_html_fillEndNoteInfo( rInfo, aParts, false );
if( rInfo.m_eNum != FTNNUM_DOC )
{
- aParts[4] = rInfo.m_eNum == FTNNUM_CHAPTER ? OUStringLiteral( u"C" ) : OUStringLiteral( u"P" );
+ aParts[4] = rInfo.m_eNum == FTNNUM_CHAPTER ? std::u16string_view( u"C" ) : std::u16string_view( u"P" );
nParts = 5;
}
if( rInfo.m_ePos != FTNPOS_PAGE)
diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index 44b43a1f864d..d9cd199c0fee 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -18,6 +18,7 @@
*/
#include <memory>
+#include <string_view>
#include <svl/itemiter.hxx>
#include <vcl/svapp.hxx>
#include <vcl/outdev.hxx>
@@ -2194,7 +2195,7 @@ void WW8FormulaControl::FormulaRead(SwWw8ControlType nWhich,
{
if ( iRes != 25 )
mnChecked = iRes;
- msDefault = ( wDef == 0 ) ? OUStringLiteral( u"0" ) : OUStringLiteral( u"1" );
+ msDefault = ( wDef == 0 ) ? std::u16string_view( u"0" ) : std::u16string_view( u"1" );
}
}
// xstzTextFormat
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index b987c948bd6d..45e2a844da18 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -10801,7 +10801,8 @@ sal_Int32 PDFWriterImpl::createControl( const PDFWriter::AnyWidget& rControl, sa
rNewWidget.m_nTextStyle =
DrawTextFlags::VCenter | DrawTextFlags::MultiLine | DrawTextFlags::WordBreak;
- rNewWidget.m_aValue = rBox.Checked ? OUStringLiteral(u"Yes") : OUStringLiteral(u"Off" );
+ rNewWidget.m_aValue
+ = rBox.Checked ? std::u16string_view(u"Yes") : std::u16string_view(u"Off" );
// create default appearance before m_aRect gets transformed
createDefaultCheckBoxAppearance( rNewWidget, rBox );
}
diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.cxx b/writerfilter/source/dmapper/TablePropertiesHandler.cxx
index b2cb476e3623..5c31f0e77367 100644
--- a/writerfilter/source/dmapper/TablePropertiesHandler.cxx
+++ b/writerfilter/source/dmapper/TablePropertiesHandler.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <string_view>
+
#include "BorderHandler.hxx"
#include "CellColorHandler.hxx"
#include "CellMarginHandler.hxx"
@@ -369,7 +373,7 @@ namespace writerfilter::dmapper {
if (m_pCurrentInteropGrabBag)
{
beans::PropertyValue aValue;
- aValue.Name = (nSprmId == NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize ? OUStringLiteral(u"tblStyleRowBandSize") : OUStringLiteral(u"tblStyleColBandSize"));
+ aValue.Name = (nSprmId == NS_ooxml::LN_CT_TblPrBase_tblStyleRowBandSize ? std::u16string_view(u"tblStyleRowBandSize") : std::u16string_view(u"tblStyleColBandSize"));
aValue.Value <<= nIntValue;
m_pCurrentInteropGrabBag->push_back(aValue);
}
diff --git a/writerfilter/source/rtftok/rtfdispatchflag.cxx b/writerfilter/source/rtftok/rtfdispatchflag.cxx
index 7bfa56d42d7c..2acb4d59f977 100644
--- a/writerfilter/source/rtftok/rtfdispatchflag.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchflag.cxx
@@ -7,6 +7,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <sal/config.h>
+
+#include <string_view>
+
#include "rtfdocumentimpl.hxx"
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
@@ -1045,8 +1049,8 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
{
beans::PropertyValue aPropertyValue;
aPropertyValue.Name
- = (nKeyword == RTFKeyword::DOBXMARGIN ? OUStringLiteral(u"HoriOrientRelation")
- : OUStringLiteral(u"VertOrientRelation"));
+ = (nKeyword == RTFKeyword::DOBXMARGIN ? std::u16string_view(u"HoriOrientRelation")
+ : std::u16string_view(u"VertOrientRelation"));
aPropertyValue.Value <<= text::RelOrientation::PAGE_PRINT_AREA;
m_aStates.top().getDrawingObject().getPendingProperties().push_back(aPropertyValue);
}
@@ -1056,8 +1060,8 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
{
beans::PropertyValue aPropertyValue;
aPropertyValue.Name
- = (nKeyword == RTFKeyword::DOBXPAGE ? OUStringLiteral(u"HoriOrientRelation")
- : OUStringLiteral(u"VertOrientRelation"));
+ = (nKeyword == RTFKeyword::DOBXPAGE ? std::u16string_view(u"HoriOrientRelation")
+ : std::u16string_view(u"VertOrientRelation"));
aPropertyValue.Value <<= text::RelOrientation::PAGE_FRAME;
m_aStates.top().getDrawingObject().getPendingProperties().push_back(aPropertyValue);
}