include/sax/fastattribs.hxx | 1 + sax/source/tools/fastattribs.cxx | 7 +++++++ writerfilter/source/ooxml/OOXMLFactory.cxx | 2 +- writerfilter/source/ooxml/OOXMLFactory.hxx | 2 +- writerfilter/source/ooxml/factory_ns.py | 2 +- writerfilter/source/ooxml/factoryimpl_ns.py | 14 +++++++------- 6 files changed, 18 insertions(+), 10 deletions(-)
New commits: commit 28dc1e713cfc5b5ea38e15f032aba72d05e40b33 Author: Noel Grandin <[email protected]> AuthorDate: Wed Jul 27 17:56:28 2022 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Thu Jul 28 08:47:41 2022 +0200 tdf#119840 remove some OUString allocation Change-Id: I488db37b3a60feb351d1ecd46278f6d5c3cdde5b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137535 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/include/sax/fastattribs.hxx b/include/sax/fastattribs.hxx index 57619b922518..24133a4f82ca 100644 --- a/include/sax/fastattribs.hxx +++ b/include/sax/fastattribs.hxx @@ -106,6 +106,7 @@ public: bool getAsChar( sal_Int32 nToken, const char*& rPos ) const; sal_Int32 getAsIntegerByIndex( sal_Int32 nTokenIndex ) const; const char* getAsCharByIndex( sal_Int32 nTokenIndex ) const; + std::string_view getAsViewByIndex( sal_Int32 nTokenIndex ) const; OUString getValueByIndex( sal_Int32 nTokenIndex ) const; // XFastAttributeList diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx index 81dabf727ebd..3522f38f3ef5 100644 --- a/sax/source/tools/fastattribs.cxx +++ b/sax/source/tools/fastattribs.cxx @@ -263,6 +263,13 @@ const char* FastAttributeList::getAsCharByIndex( sal_Int32 nTokenIndex ) const return mpChunk + nOffset; } +std::string_view FastAttributeList::getAsViewByIndex( sal_Int32 nTokenIndex ) const +{ + sal_Int32 nOffset = maAttributeValues[nTokenIndex]; + size_t nValueLen = maAttributeValues[nTokenIndex + 1] - maAttributeValues[nTokenIndex] - 1; + return { mpChunk + nOffset, nValueLen }; +} + OUString FastAttributeList::getValue( ::sal_Int32 Token ) { for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i) diff --git a/writerfilter/source/ooxml/OOXMLFactory.cxx b/writerfilter/source/ooxml/OOXMLFactory.cxx index 9e52c2b4c9e6..efedbe56d285 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.cxx +++ b/writerfilter/source/ooxml/OOXMLFactory.cxx @@ -90,7 +90,7 @@ void OOXMLFactory::attributes(OOXMLFastContextHandler * pHandler, break; case ResourceType::List: if (sal_uInt32 nValue; - pFactory->getListValue(pAttr->m_nRef, rAttribs.getValueByIndex(nAttrIndex), nValue)) + pFactory->getListValue(pAttr->m_nRef, rAttribs.getAsViewByIndex(nAttrIndex), nValue)) { xValue = OOXMLIntegerValue::Create(nValue); } diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx index 4f3c82f1b070..f687f3b6735c 100644 --- a/writerfilter/source/ooxml/OOXMLFactory.hxx +++ b/writerfilter/source/ooxml/OOXMLFactory.hxx @@ -72,7 +72,7 @@ protected: virtual ~OOXMLFactory_ns() override; public: - virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) = 0; + virtual bool getListValue(Id nId, std::string_view aValue, sal_uInt32& rOutValue) = 0; virtual Id getResourceId(Id nDefine, sal_Int32 nToken) = 0; virtual const AttributeInfo* getAttributeInfoArray(Id nId) = 0; virtual bool getElementId(Id nDefine, Id nId, ResourceType& rOutResource, Id& rOutElement) = 0; diff --git a/writerfilter/source/ooxml/factory_ns.py b/writerfilter/source/ooxml/factory_ns.py index 1d9924e239c2..18b07aba1c62 100644 --- a/writerfilter/source/ooxml/factory_ns.py +++ b/writerfilter/source/ooxml/factory_ns.py @@ -37,7 +37,7 @@ public: virtual const AttributeInfo* getAttributeInfoArray(Id nId); virtual bool getElementId(Id nDefine, Id nId, ResourceType& rOutResource, Id& rOutElement); - virtual bool getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue); + virtual bool getListValue(Id nId, std::string_view aValue, sal_uInt32& rOutValue); virtual Id getResourceId(Id nDefine, sal_Int32 nToken); """ % nsToken) diff --git a/writerfilter/source/ooxml/factoryimpl_ns.py b/writerfilter/source/ooxml/factoryimpl_ns.py index b17e0c8ffa97..263da3ebe9dc 100644 --- a/writerfilter/source/ooxml/factoryimpl_ns.py +++ b/writerfilter/source/ooxml/factoryimpl_ns.py @@ -223,13 +223,13 @@ def printValueData(values): if "" in values: output_else = "" for i in values[""]: - print(" %sif (rValue == \"%s\") { rOutValue = %s; return true; }" % (output_else, i[0], i[1])) + print(" %sif (aValue == \"%s\") { rOutValue = %s; return true; }" % (output_else, i[0], i[1])) output_else = "else " - print(" else switch (rValue[0])") + print(" else switch (aValue[0])") else: - print(" if (rValue.isEmpty())") + print(" if (aValue.empty())") print(" return false;") - print(" switch (rValue[0])") + print(" switch (aValue[0])") print(" {") for k in sorted(values.keys()): @@ -237,7 +237,7 @@ def printValueData(values): print(" case '%s':" % k) output_else = "" for i in values[k]: - print(" %sif (rValue == \"%s\") { rOutValue = %s; }" % (output_else, i[0], i[1])) + print(" %sif (aValue == \"%s\") { rOutValue = %s; }" % (output_else, i[0], i[1])) output_else = "else " print(" else { return false; }") print(" return true;") @@ -245,9 +245,9 @@ def printValueData(values): def factoryGetListValue(nsNode): - print("""bool OOXMLFactory_%s::getListValue(Id nId, const OUString& rValue, sal_uInt32& rOutValue) + print("""bool OOXMLFactory_%s::getListValue(Id nId, std::string_view aValue, sal_uInt32& rOutValue) { - (void) rValue; + (void) aValue; (void) rOutValue; switch (nId)
