diff base/XmlExportable.cpp @ 1677:f97d64b8674f single-point

Make XmlExportables store their export IDs and always obtain a new one, avoiding reuse when an object is allocated at the same heap location as a previous one. This makes the ID system stable enough to be used in the export tests.
author Chris Cannam
date Thu, 28 Mar 2019 11:55:02 +0000
parents 48e9f538e6e9
children e4f31f506116
line wrap: on
line diff
--- a/base/XmlExportable.cpp	Thu Mar 28 10:39:24 2019 +0000
+++ b/base/XmlExportable.cpp	Thu Mar 28 11:55:02 2019 +0000
@@ -68,19 +68,17 @@
 }
 
 int
-XmlExportable::getObjectExportId(const void * object)
+XmlExportable::getExportId() const
 {
-    static QMutex mutex;
-    QMutexLocker locker(&mutex);
-
-    static std::map<const void *, int> idMap;
-    static int maxId = 0;
-    
-    if (idMap.find(object) == idMap.end()) {
-        idMap[object] = maxId++;
+    if (m_exportId == -1) {
+        static QMutex mutex;
+        static int lastId = 0;
+        QMutexLocker locker(&mutex);
+        if (m_exportId == -1) {
+            m_exportId = ++lastId;
+        }
     }
-
-    return idMap[object];
+    return m_exportId;
 }