changeset 5673:ebcbb448bea8 find-refactoring

improved memory
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 06 Jul 2024 14:31:22 +0200
parents e300f22a46f0
children 74f3aab95886
files OrthancServer/Sources/Database/FindResponse.cpp OrthancServer/Sources/Database/FindResponse.h
diffstat 2 files changed, 30 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/FindResponse.cpp	Sat Jul 06 14:24:45 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.cpp	Sat Jul 06 14:31:22 2024 +0200
@@ -142,6 +142,22 @@
   }
 
 
+  FindResponse::ChildrenInformation::~ChildrenInformation()
+  {
+    for (MetadataValues::iterator it = metadataValues_.begin(); it != metadataValues_.end(); ++it)
+    {
+      assert(it->second != NULL);
+      delete it->second;
+    }
+
+    for (MainDicomTagValues::iterator it = mainDicomTagValues_.begin(); it != mainDicomTagValues_.end(); ++it)
+    {
+      assert(it->second != NULL);
+      delete it->second;
+    }
+  }
+
+
   void FindResponse::ChildrenInformation::AddIdentifier(const std::string& identifier)
   {
     if (identifiers_.find(identifier) == identifiers_.end())
@@ -164,11 +180,12 @@
     {
       std::set<std::string> s;
       s.insert(value);
-      metadataValues_[metadata] = s;
+      metadataValues_[metadata] = new std::set(s);
     }
     else
     {
-      found->second.insert(value);
+      assert(found->second != NULL);
+      found->second->insert(value);
     }
   }
 
@@ -184,7 +201,8 @@
     }
     else
     {
-      values = found->second;
+      assert(found->second != NULL);
+      values = *found->second;
     }
   }
 
@@ -198,11 +216,12 @@
     {
       std::set<std::string> s;
       s.insert(value);
-      mainDicomTagValues_[tag] = s;
+      mainDicomTagValues_[tag] = new std::set(s);
     }
     else
     {
-      found->second.insert(value);
+      assert(found->second != NULL);
+      found->second->insert(value);
     }
   }
 
@@ -218,7 +237,8 @@
     }
     else
     {
-      values = found->second;
+      assert(found->second != NULL);
+      values = *found->second;
     }
   }
 
--- a/OrthancServer/Sources/Database/FindResponse.h	Sat Jul 06 14:24:45 2024 +0200
+++ b/OrthancServer/Sources/Database/FindResponse.h	Sat Jul 06 14:31:22 2024 +0200
@@ -69,14 +69,16 @@
     class ChildrenInformation : public boost::noncopyable
     {
     private:
-      typedef std::map<MetadataType, std::set<std::string> >  MetadataValues;
-      typedef std::map<DicomTag, std::set<std::string> >      MainDicomTagValues;
+      typedef std::map<MetadataType, std::set<std::string>* >  MetadataValues;
+      typedef std::map<DicomTag, std::set<std::string>* >      MainDicomTagValues;
 
       std::set<std::string>  identifiers_;
       MetadataValues         metadataValues_;
       MainDicomTagValues     mainDicomTagValues_;
 
     public:
+      ~ChildrenInformation();
+
       void AddIdentifier(const std::string& identifier);
 
       const std::set<std::string>& GetIdentifiers() const