From 8671323bd99de01bffef91081756822d7b5c2431 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <dmitri.naumov@ufz.de> Date: Fri, 21 Jun 2019 18:42:16 +0200 Subject: [PATCH] [App/DE] Color: Use map's find algorithm. This is much faster and more readable. --- Applications/DataHolderLib/Color.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Applications/DataHolderLib/Color.cpp b/Applications/DataHolderLib/Color.cpp index ebc31eb04ae..13ff618f80d 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 -- GitLab