Skip to content
Snippets Groups Projects
Commit a0ee9eda authored by Franck Dary's avatar Franck Dary
Browse files

Only inserts in Dict if the element is not already present

parent c34cbafb
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment