mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-05-18 19:37:35 +02:00
Merge pull request #593 from AlB80/master
Optimize Value::isIntegral() method
This commit is contained in:
commit
f7df408a6a
@ -1360,11 +1360,23 @@ bool Value::isUInt64() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Value::isIntegral() const {
|
bool Value::isIntegral() const {
|
||||||
|
switch (type_) {
|
||||||
|
case intValue:
|
||||||
|
case uintValue:
|
||||||
|
return true;
|
||||||
|
case realValue:
|
||||||
#if defined(JSON_HAS_INT64)
|
#if defined(JSON_HAS_INT64)
|
||||||
return isInt64() || isUInt64();
|
// Note that maxUInt64 (= 2^64 - 1) is not exactly representable as a
|
||||||
|
// double, so double(maxUInt64) will be rounded up to 2^64. Therefore we
|
||||||
|
// require the value to be strictly less than the limit.
|
||||||
|
return value_.real_ >= double(minInt64) && value_.real_ < maxUInt64AsDouble && IsIntegral(value_.real_);
|
||||||
#else
|
#else
|
||||||
return isInt() || isUInt();
|
return value_.real_ >= minInt && value_.real_ <= maxUInt && IsIntegral(value_.real_);
|
||||||
#endif
|
#endif // JSON_HAS_INT64
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Value::isDouble() const { return type_ == intValue || type_ == uintValue || type_ == realValue; }
|
bool Value::isDouble() const { return type_ == intValue || type_ == uintValue || type_ == realValue; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user