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>
This commit is contained in:
Julien Nabet
2019-10-06 00:28:13 +02:00
parent 892851fe0c
commit def0096124
2 changed files with 12 additions and 0 deletions
+2
View File
@@ -22,6 +22,7 @@
#include <sal/config.h>
#include <unordered_map>
#include <stack>
#include <vector>
@@ -172,6 +173,7 @@ private:
void * fileAddress_;
NamespaceIris namespaceIris_;
NamespaceList namespaces_;
mutable std::unordered_map<OUString, int> cacheNSIds_;
ElementStack elements_;
char const * pos_;
char const * end_;
+10
View File
@@ -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;
}