From 6cc7a2c0933d2c55f052cac7d846f4525842b96d Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Mon, 23 Jan 2017 23:54:09 +0100 Subject: [PATCH] fix(color_util): Use lambda --- include/utils/color.hpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/include/utils/color.hpp b/include/utils/color.hpp index 6c0c6752..59650437 100644 --- a/include/utils/color.hpp +++ b/include/utils/color.hpp @@ -58,9 +58,7 @@ namespace color_util { template string hex(unsigned int color) { - string hex; - - if (!g_cache_hex.check(color)) { + return *g_cache_hex.object(color, [&] { char s[12]; size_t len = 0; @@ -75,10 +73,8 @@ namespace color_util { len = snprintf(s, sizeof(s), "#%02x%02x%02x", r, g, b); } - hex = string(s, len); - } - - return *g_cache_hex.object(color, hex); + return string(s, len); + }()); } inline string parse_hex(string hex) {