diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-09-12 14:34:26 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-09-12 23:09:23 +0200 |
commit | 3a37d8320c0b8a7bced8e67f7ed2581d4013e38b (patch) | |
tree | 17ca2d40fa7adf23d732694db49aaad9d7ff6918 /sax | |
parent | 128b19c33088dcd3dab55074a70a545e4b47a190 (diff) |
Optimize TokenMap and AttributeList in oox and xo
Shaves lots of string allocations, and uses optimized code paths
Change-Id: I8e33e2aecdc7e0d2f2c31b774daa36304b3973ac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173179
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sax')
-rw-r--r-- | sax/qa/cppunit/parser.cxx | 2 | ||||
-rw-r--r-- | sax/qa/cppunit/xmlimport.cxx | 9 | ||||
-rw-r--r-- | sax/source/tools/fastattribs.cxx | 16 |
3 files changed, 14 insertions, 13 deletions
diff --git a/sax/qa/cppunit/parser.cxx b/sax/qa/cppunit/parser.cxx index 670c1afa9277..288a91eefda0 100644 --- a/sax/qa/cppunit/parser.cxx +++ b/sax/qa/cppunit/parser.cxx @@ -37,7 +37,7 @@ public: CPPUNIT_ASSERT_MESSAGE( "getUTF8Identifier: unexpected call", false ); return uno::Sequence<sal_Int8>(); } - virtual sal_Int32 getTokenDirect( const char * /* pToken */, sal_Int32 /* nLength */ ) const override + virtual sal_Int32 getTokenDirect(std::string_view /* token */) const override { return -1; } diff --git a/sax/qa/cppunit/xmlimport.cxx b/sax/qa/cppunit/xmlimport.cxx index 963fa97f6893..18f8c9a21112 100644 --- a/sax/qa/cppunit/xmlimport.cxx +++ b/sax/qa/cppunit/xmlimport.cxx @@ -262,7 +262,7 @@ public: virtual Sequence< sal_Int8 > SAL_CALL getUTF8Identifier( sal_Int32 nToken ) override; virtual sal_Int32 SAL_CALL getTokenFromUTF8( const css::uno::Sequence< sal_Int8 >& Identifier ) override; //FastTokenHandlerBase - virtual sal_Int32 getTokenDirect( const char *pToken, sal_Int32 nLength ) const override; + virtual sal_Int32 getTokenDirect(std::string_view sToken) const override; }; const std::string_view DummyTokenHandler::tokens[] = { @@ -304,13 +304,12 @@ Sequence< sal_Int8 > DummyTokenHandler::getUTF8Identifier( sal_Int32 nToken ) sal_Int32 DummyTokenHandler::getTokenFromUTF8( const uno::Sequence< sal_Int8 >& rIdentifier ) { - return getTokenDirect( reinterpret_cast< const char* >( - rIdentifier.getConstArray() ), rIdentifier.getLength() ); + return getTokenDirect(std::string_view( + reinterpret_cast<const char*>(rIdentifier.getConstArray()), rIdentifier.getLength())); } -sal_Int32 DummyTokenHandler::getTokenDirect( const char* pToken, sal_Int32 nLength ) const +sal_Int32 DummyTokenHandler::getTokenDirect(std::string_view sToken) const { - std::string_view sToken( pToken, nLength ); for( size_t i = 0; i < std::size(tokens); i++ ) { if ( tokens[i] == sToken ) diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx index 45e2e9c5ebba..ceda451bafc5 100644 --- a/sax/source/tools/fastattribs.cxx +++ b/sax/source/tools/fastattribs.cxx @@ -172,9 +172,7 @@ sal_Int32 FastAttributeList::getValueToken( ::sal_Int32 Token ) { for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i) if (maAttributeTokens[i] == Token) - return FastTokenHandlerBase::getTokenFromChars( - mpTokenHandler, - getAsViewByIndex(i) ); + return getValueTokenByIndex(i); throw SAXException("FastAttributeList::getValueToken: unknown token " + OUString::number(Token), nullptr, Any()); } @@ -183,9 +181,7 @@ sal_Int32 FastAttributeList::getOptionalValueToken( ::sal_Int32 Token, ::sal_Int { for (size_t i = 0, n = maAttributeTokens.size(); i < n; ++i) if (maAttributeTokens[i] == Token) - return FastTokenHandlerBase::getTokenFromChars( - mpTokenHandler, - getAsViewByIndex(i) ); + return getValueTokenByIndex(i); return Default; } @@ -246,6 +242,12 @@ OUString FastAttributeList::getOptionalValue( ::sal_Int32 Token ) return OUString(); } + +sal_Int32 FastAttributeList::getValueTokenByIndex(sal_Int32 nTokenIndex) const +{ + return FastTokenHandlerBase::getTokenFromChars(mpTokenHandler, getAsViewByIndex(nTokenIndex)); +} + Sequence< Attribute > FastAttributeList::getUnknownAttributes( ) { auto nSize = maUnknownAttributes.size(); @@ -282,7 +284,7 @@ sal_Int32 FastTokenHandlerBase::getTokenFromChars( const FastTokenHandlerBase *pTokenHandler, std::string_view token ) { - return pTokenHandler->getTokenDirect(token.data(), token.size()); + return pTokenHandler->getTokenDirect(token); } } |