74429251b4c7 — Chris Cannam 9 years ago
* Create hashes on demand only
3 files changed, 16 insertions(+), 9 deletions(-)

M Uri.cpp
M Uri.h
M objectmapper/ObjectLoader.cpp
M Uri.cpp +1 -1
@@ 51,7 51,7 @@ namespace Dataquay
 {
 
 void
-ImmutableString::makeHash() 
+ImmutableString::makeHash() const
 {
     m_hash = qHash(m_s);
 }

          
M Uri.h +9 -8
@@ 59,12 59,10 @@ namespace Dataquay
 class ImmutableString
 {
 public:
-    ImmutableString() {
-        makeHash();
+    ImmutableString() : m_hash(0) {
     }
 
-    ImmutableString(const QString &s) : m_s(s) {
-        makeHash();
+    ImmutableString(const QString &s) : m_hash(0), m_s(s) {
     }
 
     ~ImmutableString() {

          
@@ 72,10 70,13 @@ public:
 
     inline QString toString() const { return m_s; }
     inline int length() const { return m_s.length(); }
-    inline unsigned int hash() const { return m_hash; }
+    inline unsigned int hash() const {
+        if (!m_hash) makeHash();
+        return m_hash;
+    }
 
     inline bool operator==(const ImmutableString &is) const {
-        if (m_hash != is.m_hash) return false;
+        if (hash() != is.hash()) return false;
         else return stringsEqual(is);
     }
     inline bool operator!=(const ImmutableString &is) const {

          
@@ 90,8 91,8 @@ public:
 
 private:
     bool stringsEqual(const ImmutableString &) const;
-    void makeHash();
-    unsigned int m_hash;
+    void makeHash() const;
+    mutable unsigned int m_hash;
     QString m_s;
 };
 

          
M objectmapper/ObjectLoader.cpp +6 -0
@@ 416,6 416,8 @@ private:
         foreach (Node n, state.toPopulate) DEBUG << n;
 
         DEBUG << endl;
+
+        std::cerr << "collect done" << std::endl;
     }
 
     bool nodeHasTypeInStore(Node node) {

          
@@ 538,18 540,22 @@ private:
                 }
             }
         }
+        std::cerr << "allocate done" << std::endl;
         foreach (Node node, state.toInitialise) {
             DEBUG << "load: calling initialise(" << node << ")" << endl;
             initialise(state, node);
         }
+        std::cerr << "initialise done" << std::endl;
         foreach (Node node, state.toPopulate) {
             DEBUG << "load: calling populate(" << node << ")" << endl;
             populate(state, node);
         }
+        std::cerr << "populate done" << std::endl;
         foreach (Node node, state.toPopulate) {
             DEBUG << "load: calling callLoadCallbacks(" << node << ")" << endl;
             callLoadCallbacks(state, node);
         }
+        std::cerr << "load done" << std::endl;
     }
 
     QObject *parentObjectOf(LoadState &state, Node node) {