From 12e9ef32f9827d2b553ffdd7a6f67d39991051b5 Mon Sep 17 00:00:00 2001 From: "Alexander V. Brezgin" Date: Sun, 20 Nov 2016 03:28:15 +0300 Subject: [PATCH 1/3] Remove repeated condition isDouble() contains isIntegral() --- src/lib_json/json_value.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index d3c496f..f18f324 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1356,7 +1356,7 @@ bool Value::isIntegral() const { bool Value::isDouble() const { return type_ == realValue || isIntegral(); } -bool Value::isNumeric() const { return isIntegral() || isDouble(); } +bool Value::isNumeric() const { return isDouble(); } bool Value::isString() const { return type_ == stringValue; } From b4abc8241feae90586c760eb9b2b50986b817869 Mon Sep 17 00:00:00 2001 From: "Alexander V. Brezgin" Date: Sun, 20 Nov 2016 03:50:32 +0300 Subject: [PATCH 2/3] Optimize value range check --- src/lib_json/json_value.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index f18f324..1abb006 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1279,7 +1279,11 @@ bool Value::isBool() const { return type_ == booleanValue; } bool Value::isInt() const { switch (type_) { case intValue: +#if defined(JSON_HAS_INT64) return value_.int_ >= minInt && value_.int_ <= maxInt; +#else + return true; +#endif case uintValue: return value_.uint_ <= UInt(maxInt); case realValue: @@ -1294,9 +1298,17 @@ bool Value::isInt() const { bool Value::isUInt() const { switch (type_) { case intValue: +#if defined(JSON_HAS_INT64) return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt); +#else + return value_.int_ >= 0; +#endif case uintValue: +#if defined(JSON_HAS_INT64) return value_.uint_ <= maxUInt; +#else + return true; +#endif case realValue: return value_.real_ >= 0 && value_.real_ <= maxUInt && IsIntegral(value_.real_); From ee7935986e0ba0af716ef0795651d3db73bf872e Mon Sep 17 00:00:00 2001 From: "Alexander V. Brezgin" Date: Sun, 20 Nov 2016 03:55:08 +0300 Subject: [PATCH 3/3] Optimize value check --- src/lib_json/json_value.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib_json/json_value.cpp b/src/lib_json/json_value.cpp index 1abb006..9710f5b 100644 --- a/src/lib_json/json_value.cpp +++ b/src/lib_json/json_value.cpp @@ -1366,7 +1366,7 @@ bool Value::isIntegral() const { #endif } -bool Value::isDouble() const { return type_ == realValue || isIntegral(); } +bool Value::isDouble() const { return type_ == intValue || type_ == uintValue || type_ == realValue; } bool Value::isNumeric() const { return isDouble(); }