summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-07-22 16:20:16 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-07-22 23:00:53 +0200
commit2006d7455f529d3d6f44d09a83be9a80e73b1d34 (patch)
tree936875a4ac98b3d3fdca4d2c34ce1c2ecaf399db
parentf8a312617838e8626e6e406791ad8d0aac368f23 (diff)
no need to create OString temporaries when calling XmlWriter methods
Change-Id: Ief1101c55a0635dac43a7c4d66dd4ed0d5be70bd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154764 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--drawinglayer/source/tools/primitive2dxmldump.cxx4
-rw-r--r--include/tools/XmlWriter.hxx14
-rw-r--r--tools/source/xml/XmlWriter.cxx33
3 files changed, 33 insertions, 18 deletions
diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx
index a68692649f46..38e6a3ea9773 100644
--- a/drawinglayer/source/tools/primitive2dxmldump.cxx
+++ b/drawinglayer/source/tools/primitive2dxmldump.cxx
@@ -925,7 +925,7 @@ void Primitive2dXmlDump::decomposeAndWrite(
for (size_t iDx = 0; iDx < aDx.size(); ++iDx)
{
OString sName = "dx" + OString::number(iDx);
- rWriter.attribute(sName, OUString::number(aDx[iDx]));
+ rWriter.attribute(sName, OString::number(aDx[iDx]));
}
}
rWriter.endElement();
@@ -1207,7 +1207,7 @@ void Primitive2dXmlDump::decomposeAndWrite(
default:
{
- OString aName("unhandled");
+ const char* aName = "unhandled";
switch (nId)
{
case PRIMITIVE2D_ID_RANGE_SVX | 14: // PRIMITIVE2D_ID_SDRCELLPRIMITIVE2D
diff --git a/include/tools/XmlWriter.hxx b/include/tools/XmlWriter.hxx
index e8f6579b0e95..400748611bd5 100644
--- a/include/tools/XmlWriter.hxx
+++ b/include/tools/XmlWriter.hxx
@@ -44,21 +44,23 @@ public:
bool startDocument(sal_Int32 nIndent = 2, bool bWriteXmlHeader = true);
void endDocument();
+ void startElement(const char* sName);
void startElement(const OString& sName);
void startElement(const OString& sPrefix, const OString& sName, const OString& sNamespaceUri);
void endElement();
+ void attribute(const char* sTagName, const OString& aValue);
void attribute(const OString& sTagName, const OString& aValue);
- void attribute(const OString& sTagName, std::u16string_view aValue);
- void attribute(const OString& sTagName, sal_Int32 aNumber);
- void attributeDouble(const OString& sTagName, double aNumber);
- void attributeBase64(const OString& sTagName, std::vector<sal_uInt8> const& rValueInBytes);
- void attributeBase64(const OString& sTagName, std::vector<char> const& rValueInBytes);
+ void attribute(const char* sTagName, std::u16string_view aValue);
+ void attribute(const char* sTagName, sal_Int32 aNumber);
+ void attributeDouble(const char* sTagName, double aNumber);
+ void attributeBase64(const char* sTagName, std::vector<sal_uInt8> const& rValueInBytes);
+ void attributeBase64(const char* sTagName, std::vector<char> const& rValueInBytes);
void content(const OString& sValue);
void content(std::u16string_view sValue);
- void element(const OString& sName);
+ void element(const char* sName);
};
} // end tools namespace
diff --git a/tools/source/xml/XmlWriter.cxx b/tools/source/xml/XmlWriter.cxx
index a13190ecf9d2..424b13c67b01 100644
--- a/tools/source/xml/XmlWriter.cxx
+++ b/tools/source/xml/XmlWriter.cxx
@@ -93,28 +93,41 @@ void XmlWriter::startElement(const OString& sPrefix, const OString& sName,
(void)xmlTextWriterStartElementNS(mpImpl->mpWriter, xmlPrefix, xmlName, xmlNamespaceUri);
}
-void XmlWriter::startElement(const OString& sName)
+void XmlWriter::startElement(const char* pName)
{
- xmlChar* xmlName = BAD_CAST(sName.getStr());
+ xmlChar* xmlName = BAD_CAST(pName);
+ (void)xmlTextWriterStartElement(mpImpl->mpWriter, xmlName);
+}
+
+void XmlWriter::startElement(const OString& rName)
+{
+ xmlChar* xmlName = BAD_CAST(rName.getStr());
(void)xmlTextWriterStartElement(mpImpl->mpWriter, xmlName);
}
void XmlWriter::endElement() { (void)xmlTextWriterEndElement(mpImpl->mpWriter); }
-void XmlWriter::attributeBase64(const OString& rsName, std::vector<sal_uInt8> const& rValueInBytes)
+void XmlWriter::attributeBase64(const char* pName, std::vector<sal_uInt8> const& rValueInBytes)
{
std::vector<char> aSignedBytes(rValueInBytes.begin(), rValueInBytes.end());
- attributeBase64(rsName, aSignedBytes);
+ attributeBase64(pName, aSignedBytes);
}
-void XmlWriter::attributeBase64(const OString& rsName, std::vector<char> const& rValueInBytes)
+void XmlWriter::attributeBase64(const char* pName, std::vector<char> const& rValueInBytes)
{
- xmlChar* xmlName = BAD_CAST(rsName.getStr());
+ xmlChar* xmlName = BAD_CAST(pName);
(void)xmlTextWriterStartAttribute(mpImpl->mpWriter, xmlName);
(void)xmlTextWriterWriteBase64(mpImpl->mpWriter, rValueInBytes.data(), 0, rValueInBytes.size());
(void)xmlTextWriterEndAttribute(mpImpl->mpWriter);
}
+void XmlWriter::attribute(const char* name, const OString& value)
+{
+ xmlChar* xmlName = BAD_CAST(name);
+ xmlChar* xmlValue = BAD_CAST(value.getStr());
+ (void)xmlTextWriterWriteAttribute(mpImpl->mpWriter, xmlName, xmlValue);
+}
+
void XmlWriter::attribute(const OString& name, const OString& value)
{
xmlChar* xmlName = BAD_CAST(name.getStr());
@@ -122,17 +135,17 @@ void XmlWriter::attribute(const OString& name, const OString& value)
(void)xmlTextWriterWriteAttribute(mpImpl->mpWriter, xmlName, xmlValue);
}
-void XmlWriter::attribute(const OString& name, std::u16string_view value)
+void XmlWriter::attribute(const char* name, std::u16string_view value)
{
attribute(name, OUStringToOString(value, RTL_TEXTENCODING_UTF8));
}
-void XmlWriter::attribute(const OString& name, const sal_Int32 aNumber)
+void XmlWriter::attribute(const char* name, const sal_Int32 aNumber)
{
attribute(name, OString::number(aNumber));
}
-void XmlWriter::attributeDouble(const OString& name, const double aNumber)
+void XmlWriter::attributeDouble(const char* name, const double aNumber)
{
attribute(name, OString::number(aNumber));
}
@@ -148,7 +161,7 @@ void XmlWriter::content(std::u16string_view sValue)
content(OUStringToOString(sValue, RTL_TEXTENCODING_UTF8));
}
-void XmlWriter::element(const OString& sName)
+void XmlWriter::element(const char* sName)
{
startElement(sName);
endElement();