Fix copy constructor 49/312749/1
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 14 Jun 2024 00:35:00 +0000 (09:35 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 14 Jun 2024 00:35:00 +0000 (09:35 +0900)
For the wrong code written in anticipation of the order of the bundle,
the elements are taken out of the list and the values are copied.
This patc is for backward compatibility.

Change-Id: I77eb340fcac5e0b4e7fbe8946cf4bdadfc44e576
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/bundle/bundle-internal.cc

index 68ccd8e..0470413 100644 (file)
@@ -53,10 +53,9 @@ Bundle::Bundle(int argc, char** argv) {
 }
 
 Bundle::Bundle(const Bundle& b) {
-  for (const auto& [key, val] : b.map_) {
-    const KeyInfo& info = *val;
-    auto new_val = std::make_shared<KeyInfo>(info);
-    map_[key] = new_val;
+  for (const auto& info : b.list_) {
+    auto new_val = std::make_shared<KeyInfo>(*info);
+    map_[info->GetKey()] = new_val;
     list_.push_back(std::move(new_val));
   }
 }
@@ -65,10 +64,9 @@ Bundle& Bundle::operator = (const Bundle& b) {
   if (this != &b) {
     map_.clear();
     list_.clear();
-    for (const auto& [key, val] : b.map_) {
-      const KeyInfo& info = *val;
-      auto new_val = std::make_shared<KeyInfo>(info);
-      map_[key] = new_val;
+    for (const auto& info : b.list_) {
+      auto new_val = std::make_shared<KeyInfo>(*info);
+      map_[info->GetKey()] = new_val;
       list_.push_back(std::move(new_val));
     }
   }