[Libreoffice-commits] core.git: include/xmlreader xmlreader/source

Julien Nabet (via logerrit) logerrit at kemper.freedesktop.org
Sat Oct 5 22:29:25 UTC 2019


 include/xmlreader/xmlreader.hxx |    2 ++
 xmlreader/source/xmlreader.cxx  |   10 ++++++++++
 2 files changed, 12 insertions(+)

New commits:
commit def00961243da0662f394bdf58b1157cfd45dfab
Author:     Julien Nabet <serval2412 at yahoo.fr>
AuthorDate: Sat Oct 5 15:34:54 2019 +0200
Commit:     Julien Nabet <serval2412 at yahoo.fr>
CommitDate: Sun Oct 6 00:28:13 2019 +0200

    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 at yahoo.fr>

diff --git a/include/xmlreader/xmlreader.hxx b/include/xmlreader/xmlreader.hxx
index b86544e494e2..a7f7dbb6d1ce 100644
--- a/include/xmlreader/xmlreader.hxx
+++ b/include/xmlreader/xmlreader.hxx
@@ -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_;
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;
 }


More information about the Libreoffice-commits mailing list