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 <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2022-07-27 17:56:28 +02:00
parent 7ba40c7d62
commit 28dc1e713c
6 changed files with 18 additions and 10 deletions

View file

@ -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

View file

@ -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)

View file

@ -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);
}

View file

@ -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;

View file

@ -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)

View file

@ -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)