From 5c129c898158c93f751985c305296d781891d814 Mon Sep 17 00:00:00 2001 From: dtoma Date: Wed, 29 Jun 2016 19:28:56 +0800 Subject: [PATCH 1/2] 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 From 6e1347e68c9d03f3b2563ed972e77c03d688a151 Mon Sep 17 00:00:00 2001 From: Niels Date: Fri, 1 Jul 2016 16:58:50 +0200 Subject: [PATCH 2/2] fixes #270 --- README.md | 1 + src/json.hpp | 9 ++++----- src/json.hpp.re2c | 11 ++++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4ad40373b..f6b840839 100644 --- a/README.md +++ b/README.md @@ -485,6 +485,7 @@ I deeply appreciate the help of the following people. - [Tom Needham](https://github.com/06needhamt) fixed a subtle bug with MSVC 2015 which was also proposed by [Michael K.](https://github.com/Epidal). - [Mário Feroldi](https://github.com/thelostt) fixed a small typo. - [duncanwerner](https://github.com/duncanwerner) found a really embarrassing performance regression in the 2.0.0 release. +- [Damien](https://github.com/dtoma) fixed one of the last conversion warnings. Thanks a lot for helping out! diff --git a/src/json.hpp b/src/json.hpp index 35bdd293c..a6775e53e 100644 --- a/src/json.hpp +++ b/src/json.hpp @@ -5957,16 +5957,15 @@ class basic_json { // convert a number 0..15 to its hex representation // (0..f) - const auto hexify = [](const int v) -> char + static const char hexify[16] = { - return (v < 10) - ? ('0' + static_cast(v)) - : ('a' + static_cast((v - 10) & 0x1f)); + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; // print character c as \uxxxx for (const char m : - { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f) + { 'u', '0', '0', hexify[c >> 4], hexify[c & 0x0f] }) { result[++pos] = m; diff --git a/src/json.hpp.re2c b/src/json.hpp.re2c index adc2e188c..1967f6a81 100644 --- a/src/json.hpp.re2c +++ b/src/json.hpp.re2c @@ -5957,18 +5957,15 @@ class basic_json { // convert a number 0..15 to its hex representation // (0..f) - const auto hexify = [](const int v) -> char + static const char hexify[16] = { - static const char hex[16] = { '0', '1', '2', '3', - '4', '5', '6', '7', - '8', '9', 'a', 'b', - 'c', 'd', 'e', 'f' }; - return hex[v]; + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; // print character c as \uxxxx for (const char m : - { 'u', '0', '0', hexify(c >> 4), hexify(c & 0x0f) + { 'u', '0', '0', hexify[c >> 4], hexify[c & 0x0f] }) { result[++pos] = m;