From 5c129c898158c93f751985c305296d781891d814 Mon Sep 17 00:00:00 2001 From: dtoma Date: Wed, 29 Jun 2016 19:28:56 +0800 Subject: [PATCH] Update hexify to use array lookup instead of ternary (#270) --- src/json.hpp.re2c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index 016ff0c51..adc2e188c 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -5959,9 +5959,11 @@ class basic_json // (0..f) const auto hexify = [](const int v) -> char { - return (v < 10) - ? ('0' + static_cast(v)) - : ('a' + static_cast((v - 10) & 0x1f)); + static const char hex[16] = { '0', '1', '2', '3', + '4', '5', '6', '7', + '8', '9', 'a', 'b', + 'c', 'd', 'e', 'f' }; + return hex[v]; }; // print character c as \uxxxx