mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-04-21 00:11:50 +02:00
Optimize value range check
This commit is contained in:
parent
12e9ef32f9
commit
b4abc8241f
@ -1279,7 +1279,11 @@ bool Value::isBool() const { return type_ == booleanValue; }
|
|||||||
bool Value::isInt() const {
|
bool Value::isInt() const {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case intValue:
|
case intValue:
|
||||||
|
#if defined(JSON_HAS_INT64)
|
||||||
return value_.int_ >= minInt && value_.int_ <= maxInt;
|
return value_.int_ >= minInt && value_.int_ <= maxInt;
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
case uintValue:
|
case uintValue:
|
||||||
return value_.uint_ <= UInt(maxInt);
|
return value_.uint_ <= UInt(maxInt);
|
||||||
case realValue:
|
case realValue:
|
||||||
@ -1294,9 +1298,17 @@ bool Value::isInt() const {
|
|||||||
bool Value::isUInt() const {
|
bool Value::isUInt() const {
|
||||||
switch (type_) {
|
switch (type_) {
|
||||||
case intValue:
|
case intValue:
|
||||||
|
#if defined(JSON_HAS_INT64)
|
||||||
return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt);
|
return value_.int_ >= 0 && LargestUInt(value_.int_) <= LargestUInt(maxUInt);
|
||||||
|
#else
|
||||||
|
return value_.int_ >= 0;
|
||||||
|
#endif
|
||||||
case uintValue:
|
case uintValue:
|
||||||
|
#if defined(JSON_HAS_INT64)
|
||||||
return value_.uint_ <= maxUInt;
|
return value_.uint_ <= maxUInt;
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
case realValue:
|
case realValue:
|
||||||
return value_.real_ >= 0 && value_.real_ <= maxUInt &&
|
return value_.real_ >= 0 && value_.real_ <= maxUInt &&
|
||||||
IsIntegral(value_.real_);
|
IsIntegral(value_.real_);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user