Optimize a bit, to avoid a copy of the vector

Change-Id: I747662e346151e2e055cb803278c2a6c7709f273
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166166
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski 2024-04-15 08:19:25 +01:00
parent 00c13dfcdb
commit 3e38fdacba

View file

@ -29,6 +29,15 @@ int funcCloseCallback(void* pContext)
return 0; // 0 or -1 in case of error return 0; // 0 or -1 in case of error
} }
template <typename T>
requires(sizeof(T) == sizeof(char)) void attributeBase64_impl(xmlTextWriterPtr writer,
const char* name, const T* value,
int size)
{
(void)xmlTextWriterStartAttribute(writer, BAD_CAST(name));
(void)xmlTextWriterWriteBase64(writer, reinterpret_cast<const char*>(value), 0, size);
(void)xmlTextWriterEndAttribute(writer);
}
} // end anonymous namespace } // end anonymous namespace
struct XmlWriterImpl struct XmlWriterImpl
@ -103,16 +112,12 @@ void XmlWriter::endElement() { (void)xmlTextWriterEndElement(mpImpl->mpWriter);
void XmlWriter::attributeBase64(const char* pName, 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_impl(mpImpl->mpWriter, pName, rValueInBytes.data(), rValueInBytes.size());
attributeBase64(pName, aSignedBytes);
} }
void XmlWriter::attributeBase64(const char* pName, std::vector<char> const& rValueInBytes) void XmlWriter::attributeBase64(const char* pName, std::vector<char> const& rValueInBytes)
{ {
xmlChar* xmlName = BAD_CAST(pName); attributeBase64_impl(mpImpl->mpWriter, pName, rValueInBytes.data(), rValueInBytes.size());
(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) void XmlWriter::attribute(const char* name, const OString& value)