Closed ctasada closed 1 month ago
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
Purpose
Fixes a performance issue while using the
ToNumberPolicy.LONG_OR_DOUBLE
withDouble
valuesDescription
The Parsing of a Double value was always executing a
Long.parseLong(value)
, which generated aNumberFormatException
.Identifying that a Number is a Double or a Long can be easily achieve (in a naive way) looking for the decimal separator.
This simple change avoids the extra
NumberFormatException
A simple JUnit test, parsing a
Long
or aDouble
10K times shows the next values:As we can see, the parsing for
Long
values stays the same (±1ms), while the parsing forDouble
is dramatically improved.Reducing the number of exceptions also has a positive side effect in memory consumption.
Checklist
mvn verify
, but can also be checked on its own usingmvn spotless:check
.\ Style violations can be fixed usingmvn spotless:apply
; this can be done in a separate commit to verify that it did not cause undesired changes.null
@since $next-version$
(
$next-version$
is a special placeholder which is automatically replaced during release)TestCase
)mvn clean verify javadoc:jar
passes without errors