diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-05 12:33:51 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-07-08 11:48:05 +0200 |
commit | a2193f8f33565cc896592acb9d3ab65c756d97fb (patch) | |
tree | f5b8fe7cfe1710b452794dede14451ad5f9abe6e /sax | |
parent | 8164399df0df976784ddc1a76b46939c53ae51ee (diff) |
tdf#79878 perf loading docx file, sax improvements
these are the smaller improvements, they make about 5% worth of
difference
- use std::vector instead of std::deque
- use std::move on pendingCharacters instead of copying
- in FastAttributeList::add, when reallocate the buffer, allocate twice
the existing size, instead of increasing to only what we need
- in FastAttributeList, create getAttributeIndex and friends, so
we can avoid iterating the attribute list more often than necessary
Change-Id: I3e3380ea50b77c6845b66e83404e245778ec06eb
Reviewed-on: https://gerrit.libreoffice.org/57021
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sax')
-rw-r--r-- | sax/source/fastparser/fastparser.cxx | 13 | ||||
-rw-r--r-- | sax/source/tools/fastattribs.cxx | 18 |
2 files changed, 24 insertions, 7 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx index 2765584a08fc..9477559c12e8 100644 --- a/sax/source/fastparser/fastparser.cxx +++ b/sax/source/fastparser/fastparser.cxx @@ -178,13 +178,13 @@ struct Entity : public ParserData void throwException( const ::rtl::Reference< FastLocatorImpl > &xDocumentLocator, bool mbDuringParse ); - std::stack< NameWithToken > maNamespaceStack; + std::stack< NameWithToken, std::vector<NameWithToken> > maNamespaceStack; /* Context for main thread consuming events. * startElement() stores the data, which characters() and endElement() uses */ - std::stack< SaxContext> maContextStack; + std::stack< SaxContext, std::vector<SaxContext> > maContextStack; // Determines which elements of maNamespaceDefines are valid in current context - std::stack< sal_uInt32 > maNamespaceCount; + std::stack< sal_uInt32, std::vector<sal_uInt32> > maNamespaceCount; std::vector< std::shared_ptr< NamespaceDefine > > maNamespaceDefines; @@ -270,7 +270,7 @@ private: ParserData maData; /// Cached parser configuration for next call of parseStream(). Entity *mpTop; /// std::stack::top() is amazingly slow => cache this. - std::stack< Entity > maEntities; /// Entity stack for each call of parseStream(). + std::stack< Entity > maEntities; /// Entity stack for each call of parseStream(). OUString pendingCharacters; /// Data from characters() callback that needs to be sent. }; @@ -674,11 +674,12 @@ sal_Int32 FastSaxParserImpl::GetTokenWithPrefix( const xmlChar* pPrefix, int nPr sal_uInt32 nNamespace = rEntity.maNamespaceCount.top(); while( nNamespace-- ) { - const OString& rPrefix( rEntity.maNamespaceDefines[nNamespace]->maPrefix ); + const auto & rNamespaceDefine = rEntity.maNamespaceDefines[nNamespace]; + const OString& rPrefix( rNamespaceDefine->maPrefix ); if( (rPrefix.getLength() == nPrefixLen) && (strncmp( rPrefix.getStr(), XML_CAST( pPrefix ), nPrefixLen ) == 0 ) ) { - nNamespaceToken = rEntity.maNamespaceDefines[nNamespace]->mnToken; + nNamespaceToken = rNamespaceDefine->mnToken; break; } diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx index a9f0baf7a2c0..30a764368947 100644 --- a/sax/source/tools/fastattribs.cxx +++ b/sax/source/tools/fastattribs.cxx @@ -86,7 +86,7 @@ void FastAttributeList::add( sal_Int32 nToken, const sal_Char* pValue, size_t nV maAttributeValues.push_back( maAttributeValues.back() + nValueLength + 1 ); if (maAttributeValues.back() > mnChunkLength) { - mnChunkLength = maAttributeValues.back(); + mnChunkLength = std::max(mnChunkLength * 2, maAttributeValues.back()); mpChunk = static_cast<sal_Char *>(realloc( mpChunk, mnChunkLength )); } strncpy(mpChunk + nWritePosition, pValue, nValueLength); @@ -166,6 +166,11 @@ bool FastAttributeList::getAsInteger( sal_Int32 nToken, sal_Int32 &rInt) const return false; } +sal_Int32 FastAttributeList::getAsIntegerByIndex( sal_Int32 nTokenIndex ) const +{ + return rtl_str_toInt32( getFastAttributeValue(nTokenIndex), 10 ); +} + bool FastAttributeList::getAsDouble( sal_Int32 nToken, double &rDouble) const { rDouble = 0.0; @@ -193,6 +198,12 @@ bool FastAttributeList::getAsChar( sal_Int32 nToken, const char*& rPos ) const return false; } +const char* FastAttributeList::getAsCharByIndex( sal_Int32 nTokenIndex ) const +{ + sal_Int32 nOffset = maAttributeValues[nTokenIndex]; + return mpChunk + nOffset; +} + OUString FastAttributeList::getValue( ::sal_Int32 Token ) { for (size_t i = 0; i < maAttributeTokens.size(); ++i) @@ -202,6 +213,11 @@ OUString FastAttributeList::getValue( ::sal_Int32 Token ) throw SAXException(); } +OUString FastAttributeList::getValueByIndex( ::sal_Int32 nTokenIndex ) const +{ + return OUString( getFastAttributeValue(nTokenIndex), AttributeValueLength(nTokenIndex), RTL_TEXTENCODING_UTF8 ); +} + OUString FastAttributeList::getOptionalValue( ::sal_Int32 Token ) { for (size_t i = 0; i < maAttributeTokens.size(); ++i) |