diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2019-10-05 15:34:54 +0200 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2019-10-06 00:28:13 +0200 |
commit | def00961243da0662f394bdf58b1157cfd45dfab (patch) | |
tree | 56b2409c893e57a42b260e8051d90173e4b497fc /xmlreader | |
parent | 892851fe0c0490860d9aeea4b0752de52e886721 (diff) |
Optimize getNamespaceId (xmlreader)
Adding a map to cache values allows me
20s -> 13s to start LO
Change-Id: If343225def253e29696b96f223cdcb54d0d8525d
Reviewed-on: https://gerrit.libreoffice.org/80290
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Diffstat (limited to 'xmlreader')
-rw-r--r-- | xmlreader/source/xmlreader.cxx | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/xmlreader/source/xmlreader.cxx b/xmlreader/source/xmlreader.cxx index 1651f857e411..229be044662c 100644 --- a/xmlreader/source/xmlreader.cxx +++ b/xmlreader/source/xmlreader.cxx @@ -182,11 +182,21 @@ Span XmlReader::getAttributeValue(bool fullyNormalize) { } int XmlReader::getNamespaceId(Span const & prefix) const { + OUString spanString = prefix.convertFromUtf8(); + + if (auto it = cacheNSIds_.find(spanString); it != cacheNSIds_.end()) + { + return it->second; + } + auto i = std::find_if(namespaces_.crbegin(), namespaces_.crend(), [&prefix](const NamespaceData& rNamespaceData) { return prefix.equals(rNamespaceData.prefix); }); if (i != namespaces_.rend()) + { + cacheNSIds_[spanString]= i->nsId; return i->nsId; + } return NAMESPACE_UNKNOWN; } |