From a0ee9eda94312924b0da04d1aef0a70300b33785 Mon Sep 17 00:00:00 2001
From: Franck Dary <franck.dary@lis-lab.fr>
Date: Sun, 23 Feb 2020 17:12:04 +0100
Subject: [PATCH] Only inserts in Dict if the element is not already present

---
 common/src/Dict.cpp | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/common/src/Dict.cpp b/common/src/Dict.cpp
index d09f149..c451ecd 100644
--- a/common/src/Dict.cpp
+++ b/common/src/Dict.cpp
@@ -63,13 +63,17 @@ void Dict::insert(const std::string & element)
 
 int Dict::getIndexOrInsert(const std::string & element)
 {
-  if (state == State::Open)
-    insert(element);
-
   const auto & found = elementsToIndexes.find(element);
 
   if (found == elementsToIndexes.end())
+  {
+    if (state == State::Open)
+    {
+      insert(element);
+      return elementsToIndexes[element];
+    }
     return elementsToIndexes[unknownValueStr];
+  }
 
   return found->second;
 }
-- 
GitLab