Skip to content

Conversation

plokhotnyuk
Copy link
Contributor

@plokhotnyuk plokhotnyuk commented Oct 23, 2017

Problem is that 40000000000000000000 (too big to be mapped to java.langLong number in JSON) is succesfully parsed to 3106511852580896768L using current implementation from develop.

@codecov-io
Copy link

codecov-io commented Oct 23, 2017

Codecov Report

Merging #121 into master will decrease coverage by 0.14%.
The diff coverage is 46.66%.

Impacted file tree graph

@@ Coverage Diff @@ ## master #121 +/- ## ========================================== - Coverage 68.53% 68.38% -0.15%  ========================================== Files 107 107 Lines 7084 7101 +17 Branches 1347 1376 +29 ========================================== + Hits 4855 4856 +1  - Misses 1800 1806 +6  - Partials 429 439 +10
Impacted Files Coverage Δ
src/main/java/com/jsoniter/IterImpl.java 65.11% <33.33%> (-3.42%) ⬇️
src/main/java/com/jsoniter/IterImplNumber.java 81.48% <50%> (-3.82%) ⬇️
...c/main/java/com/jsoniter/IterImplForStreaming.java 70.3% <68%> (+0.48%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f5dfab1...48aed51. Read the comment docs.

Copy link
Contributor

@taowen taowen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there might be better ways to do less calculation

if (value == Long.MIN_VALUE) {
throw iter.reportError("readLongSlowPath", "value is too large for long");
if (value < multmin) {
throw iter.reportError("readIntSlowPath", "value is too large for int");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw iter.reportError("readIntSlowPath", "value is too large for int");

should be long

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed by following 2 commits

please sqash them in case of merge

value = (value << 3) + (value << 1) + ind;
if (value < 0 && value != Long.MIN_VALUE) {
value = (value << 3) + (value << 1);
if (value < limit + ind) {
Copy link
Contributor

@taowen taowen Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be we can change

if (value < limit + ind) { throw iter.reportError("readLongSlowPath", "value is too large for long"); } value -= ind;

to

value -= ind; if (value >= 0) { throw iter.reportError("readLongSlowPath", "value is too large for long"); }

if value is positive, we add additional value != Long.MIN_VALUE check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

limit + ind is required to properly detect overflow when number to parse is Long.MAX_VALUE + 1 to do not raise overflow when parsing Long.MIN_VALUE

}

static long readLongSlowPath(JsonIterator iter, long value) throws IOException {
static long readLongSlowPath(final JsonIterator iter, long value, final boolean negative) throws IOException {
Copy link
Contributor

@taowen taowen Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final boolean negative is not necessary. we can always return negative number, and make it positive from the readLong. this way saved one branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some additional param is required until we inline these slow path methods or split them on pair of methods (one for negative, other for positive)

@taowen taowen merged commit 48aed51 into json-iterator:master Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants