include/xmlreader/span.hxx      |   13 +++++++++++++
 include/xmlreader/xmlreader.hxx |   12 ++++++------
 xmlreader/source/span.cxx       |    4 ++++
 xmlreader/source/xmlreader.cxx  |    6 ++----
 4 files changed, 25 insertions(+), 10 deletions(-)

New commits:
commit 4b28b77eddfe48e709180f1ab81ac0d996796471
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Sun Oct 6 12:51:15 2019 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sun Oct 6 18:51:37 2019 +0200

    we can use Span for the cache key here
    
    Change-Id: I77894e3c5e3d68cb2a12abcc0b09f2c042664ba0
    Reviewed-on: https://gerrit.libreoffice.org/80315
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/xmlreader/span.hxx b/include/xmlreader/span.hxx
index 038241ef1133..f56059b96274 100644
--- a/include/xmlreader/span.hxx
+++ b/include/xmlreader/span.hxx
@@ -77,6 +77,19 @@ struct SAL_WARN_UNUSED OOO_DLLPUBLIC_XMLREADER Span {
     }
 
     rtl::OUString convertFromUtf8() const;
+
+    std::size_t hashCode() const;
+};
+
+}
+
+namespace std {
+
+template<>
+struct hash<::xmlreader::Span>
+{
+    std::size_t operator()(::xmlreader::Span const & s) const
+    { return s.hashCode(); }
 };
 
 }
diff --git a/include/xmlreader/xmlreader.hxx b/include/xmlreader/xmlreader.hxx
index a7f7dbb6d1ce..a553baeb6c3a 100644
--- a/include/xmlreader/xmlreader.hxx
+++ b/include/xmlreader/xmlreader.hxx
@@ -77,8 +77,8 @@ private:
     // elements_ and attributes_):
 
     struct NamespaceData {
-        Span const prefix;
-        int const nsId;
+        Span prefix;
+        int nsId;
 
         NamespaceData():
             nsId(-1) {}
@@ -90,9 +90,9 @@ private:
     typedef std::vector< NamespaceData > NamespaceList;
 
     struct ElementData {
-        Span const name;
-        NamespaceList::size_type const inheritedNamespaces;
-        int const defaultNamespaceId;
+        Span name;
+        NamespaceList::size_type inheritedNamespaces;
+        int defaultNamespaceId;
 
         ElementData(
             Span const & theName,
@@ -173,7 +173,7 @@ private:
     void * fileAddress_;
     NamespaceIris namespaceIris_;
     NamespaceList namespaces_;
-    mutable std::unordered_map<OUString, int> cacheNSIds_;
+    mutable std::unordered_map<Span, int> cacheNSIds_;
     ElementStack elements_;
     char const * pos_;
     char const * end_;
diff --git a/xmlreader/source/span.cxx b/xmlreader/source/span.cxx
index 29433c561fb7..300c0a2e99b3 100644
--- a/xmlreader/source/span.cxx
+++ b/xmlreader/source/span.cxx
@@ -46,6 +46,10 @@ OUString Span::convertFromUtf8() const {
     return OUString(s, SAL_NO_ACQUIRE);
 }
 
+std::size_t Span::hashCode() const {
+    return rtl_str_hashCode_WithLength(begin, length);
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmlreader/source/xmlreader.cxx b/xmlreader/source/xmlreader.cxx
index 0194f6c695a7..95a27a785b5c 100644
--- a/xmlreader/source/xmlreader.cxx
+++ b/xmlreader/source/xmlreader.cxx
@@ -182,9 +182,7 @@ 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())
+    if (auto it = cacheNSIds_.find(prefix); it != cacheNSIds_.end())
     {
         return it->second;
     }
@@ -194,7 +192,7 @@ int XmlReader::getNamespaceId(Span const & prefix) const {
 
     if (i != namespaces_.rend())
     {
-        cacheNSIds_[spanString]= i->nsId;
+        cacheNSIds_[i->prefix]= i->nsId;
         return i->nsId;
     }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to