diff --git a/Applications/DataHolderLib/Color.cpp b/Applications/DataHolderLib/Color.cpp index ebc31eb04ae8dbfbca8d0f4cd0ad426fa86e1b02..13ff618f80d0538755d2379455ab08f6436b3b5d 100644 --- a/Applications/DataHolderLib/Color.cpp +++ b/Applications/DataHolderLib/Color.cpp @@ -44,17 +44,15 @@ Color getRandomColor() Color const getColor(const std::string &id, std::map<std::string, Color> &colors) { - for (auto it = colors.begin(); it != colors.end(); ++it) + auto it = colors.find(id); + + if (it == end(colors)) { - if (id == it->first) - { - return it->second; - } + WARN("Key '%s' not found in color lookup table.", id.c_str()); + it = colors.insert({id, getRandomColor()}).first; } - WARN("Key '%s' not found in color lookup table.", id.c_str()); - Color c = getRandomColor(); - colors.insert(std::pair<std::string, Color>(id, c)); - return c; + + return it->second; } } // namespace DataHolderLib