Skip to content

Commit

Permalink
Merge pull request open-source-parsers#593 from AlB80/master
Browse files Browse the repository at this point in the history
Optimize Value::isIntegral() method
  • Loading branch information
cdunn2001 authored Apr 6, 2017
2 parents 86ed860 + c442fd9 commit f7df408
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/lib_json/json_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,11 +1360,23 @@ bool Value::isUInt64() const {
}

bool Value::isIntegral() const {
switch (type_) {
case intValue:
case uintValue:
return true;
case realValue:
#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
return isInt() || isUInt();
#endif
return value_.real_ >= minInt && value_.real_ <= maxUInt && IsIntegral(value_.real_);
#endif // JSON_HAS_INT64
default:
break;
}
return false;
}

bool Value::isDouble() const { return type_ == intValue || type_ == uintValue || type_ == realValue; }
Expand Down

0 comments on commit f7df408

Please sign in to comment.