diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-07-22 14:33:40 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-07-22 16:57:26 +0200 |
commit | 60d7b73d6d92eeb331cfe48734094330546477db (patch) | |
tree | 660ae63e8bfbe5f847509f803b5743ef907f416b /tools | |
parent | 9b887f63147914793f881c0cf4a730a46d6f688c (diff) |
avoid some unnecessary string copies in tools::XmlWriter
Change-Id: I5844a878f3e1d85956eae828e9093b2fd1f5a275
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154757
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/source/xml/XmlWriter.cxx | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/tools/source/xml/XmlWriter.cxx b/tools/source/xml/XmlWriter.cxx index 85fbbf99544e..a13190ecf9d2 100644 --- a/tools/source/xml/XmlWriter.cxx +++ b/tools/source/xml/XmlWriter.cxx @@ -82,28 +82,21 @@ void XmlWriter::endDocument() void XmlWriter::startElement(const OString& sPrefix, const OString& sName, const OString& sNamespaceUri) { - xmlChar* xmlName = xmlCharStrdup(sName.getStr()); + xmlChar* xmlName = BAD_CAST(sName.getStr()); xmlChar* xmlPrefix = nullptr; xmlChar* xmlNamespaceUri = nullptr; if (!sPrefix.isEmpty()) - xmlPrefix = xmlCharStrdup(sPrefix.getStr()); + xmlPrefix = BAD_CAST(sPrefix.getStr()); if (!sNamespaceUri.isEmpty()) - xmlNamespaceUri = xmlCharStrdup(sNamespaceUri.getStr()); + xmlNamespaceUri = BAD_CAST(sNamespaceUri.getStr()); (void)xmlTextWriterStartElementNS(mpImpl->mpWriter, xmlPrefix, xmlName, xmlNamespaceUri); - - xmlFree(xmlName); - if (!sPrefix.isEmpty()) - xmlFree(xmlPrefix); - if (!sNamespaceUri.isEmpty()) - xmlFree(xmlNamespaceUri); } void XmlWriter::startElement(const OString& sName) { - xmlChar* xmlName = xmlCharStrdup(sName.getStr()); + xmlChar* xmlName = BAD_CAST(sName.getStr()); (void)xmlTextWriterStartElement(mpImpl->mpWriter, xmlName); - xmlFree(xmlName); } void XmlWriter::endElement() { (void)xmlTextWriterEndElement(mpImpl->mpWriter); } @@ -116,20 +109,17 @@ void XmlWriter::attributeBase64(const OString& rsName, std::vector<sal_uInt8> co void XmlWriter::attributeBase64(const OString& rsName, std::vector<char> const& rValueInBytes) { - xmlChar* xmlName = xmlCharStrdup(rsName.getStr()); + xmlChar* xmlName = BAD_CAST(rsName.getStr()); (void)xmlTextWriterStartAttribute(mpImpl->mpWriter, xmlName); (void)xmlTextWriterWriteBase64(mpImpl->mpWriter, rValueInBytes.data(), 0, rValueInBytes.size()); (void)xmlTextWriterEndAttribute(mpImpl->mpWriter); - xmlFree(xmlName); } void XmlWriter::attribute(const OString& name, const OString& value) { - xmlChar* xmlName = xmlCharStrdup(name.getStr()); - xmlChar* xmlValue = xmlCharStrdup(value.getStr()); + xmlChar* xmlName = BAD_CAST(name.getStr()); + xmlChar* xmlValue = BAD_CAST(value.getStr()); (void)xmlTextWriterWriteAttribute(mpImpl->mpWriter, xmlName, xmlValue); - xmlFree(xmlValue); - xmlFree(xmlName); } void XmlWriter::attribute(const OString& name, std::u16string_view value) @@ -139,19 +129,18 @@ void XmlWriter::attribute(const OString& name, std::u16string_view value) void XmlWriter::attribute(const OString& name, const sal_Int32 aNumber) { - attribute(name, OUString::number(aNumber)); + attribute(name, OString::number(aNumber)); } void XmlWriter::attributeDouble(const OString& name, const double aNumber) { - attribute(name, OUString::number(aNumber)); + attribute(name, OString::number(aNumber)); } void XmlWriter::content(const OString& sValue) { - xmlChar* xmlValue = xmlCharStrdup(sValue.getStr()); + xmlChar* xmlValue = BAD_CAST(sValue.getStr()); (void)xmlTextWriterWriteString(mpImpl->mpWriter, xmlValue); - xmlFree(xmlValue); } void XmlWriter::content(std::u16string_view sValue) |