@@ -323,123 +323,135 @@ public static int updateStringCopyBound(final JsonIterator iter, final int bound
323
323
return bound ;
324
324
}
325
325
326
- static final int readPositiveInt (final JsonIterator iter , byte c ) throws IOException {
326
+ static final int readInt (final JsonIterator iter , final byte c ) throws IOException {
327
327
int ind = IterImplNumber .intDigits [c ];
328
328
if (ind == 0 ) {
329
329
IterImplForStreaming .assertNotLeadingZero (iter );
330
330
return 0 ;
331
331
}
332
332
if (ind == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
333
- throw iter .reportError ("readPositiveInt " , "expect 0~9" );
333
+ throw iter .reportError ("readInt " , "expect 0~9" );
334
334
}
335
335
if (iter .tail - iter .head > 9 ) {
336
336
int i = iter .head ;
337
337
int ind2 = IterImplNumber .intDigits [iter .buf [i ]];
338
338
if (ind2 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
339
339
iter .head = i ;
340
- return ind ;
340
+ return - ind ;
341
341
}
342
342
int ind3 = IterImplNumber .intDigits [iter .buf [++i ]];
343
343
if (ind3 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
344
344
iter .head = i ;
345
- return ind * 10 + ind2 ;
345
+ ind = ind * 10 + ind2 ;
346
+ return -ind ;
346
347
}
347
348
int ind4 = IterImplNumber .intDigits [iter .buf [++i ]];
348
349
if (ind4 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
349
350
iter .head = i ;
350
- return ind * 100 + ind2 * 10 + ind3 ;
351
+ ind = ind * 100 + ind2 * 10 + ind3 ;
352
+ return -ind ;
351
353
}
352
354
int ind5 = IterImplNumber .intDigits [iter .buf [++i ]];
353
355
if (ind5 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
354
356
iter .head = i ;
355
- return ind * 1000 + ind2 * 100 + ind3 * 10 + ind4 ;
357
+ ind = ind * 1000 + ind2 * 100 + ind3 * 10 + ind4 ;
358
+ return -ind ;
356
359
}
357
360
int ind6 = IterImplNumber .intDigits [iter .buf [++i ]];
358
361
if (ind6 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
359
362
iter .head = i ;
360
- return ind * 10000 + ind2 * 1000 + ind3 * 100 + ind4 * 10 + ind5 ;
363
+ ind = ind * 10000 + ind2 * 1000 + ind3 * 100 + ind4 * 10 + ind5 ;
364
+ return -ind ;
361
365
}
362
366
int ind7 = IterImplNumber .intDigits [iter .buf [++i ]];
363
367
if (ind7 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
364
368
iter .head = i ;
365
- return ind * 100000 + ind2 * 10000 + ind3 * 1000 + ind4 * 100 + ind5 * 10 + ind6 ;
369
+ ind = ind * 100000 + ind2 * 10000 + ind3 * 1000 + ind4 * 100 + ind5 * 10 + ind6 ;
370
+ return -ind ;
366
371
}
367
372
int ind8 = IterImplNumber .intDigits [iter .buf [++i ]];
368
373
if (ind8 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
369
374
iter .head = i ;
370
- return ind * 1000000 + ind2 * 100000 + ind3 * 10000 + ind4 * 1000 + ind5 * 100 + ind6 * 10 + ind7 ;
375
+ ind = ind * 1000000 + ind2 * 100000 + ind3 * 10000 + ind4 * 1000 + ind5 * 100 + ind6 * 10 + ind7 ;
376
+ return -ind ;
371
377
}
372
378
int ind9 = IterImplNumber .intDigits [iter .buf [++i ]];
373
379
ind = ind * 10000000 + ind2 * 1000000 + ind3 * 100000 + ind4 * 10000 + ind5 * 1000 + ind6 * 100 + ind7 * 10 + ind8 ;
374
380
iter .head = i ;
375
381
if (ind9 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
376
- return ind ;
382
+ return - ind ;
377
383
}
378
384
}
379
385
return IterImplForStreaming .readIntSlowPath (iter , ind );
380
386
}
381
387
382
- static final long readPositiveLong (final JsonIterator iter , byte c ) throws IOException {
388
+ static final long readLong (final JsonIterator iter , final byte c ) throws IOException {
383
389
long ind = IterImplNumber .intDigits [c ];
384
390
if (ind == 0 ) {
385
391
IterImplForStreaming .assertNotLeadingZero (iter );
386
392
return 0 ;
387
393
}
388
394
if (ind == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
389
- throw iter .reportError ("readPositiveLong " , "expect 0~9" );
395
+ throw iter .reportError ("readLong " , "expect 0~9" );
390
396
}
391
397
if (iter .tail - iter .head > 9 ) {
392
398
int i = iter .head ;
393
399
int ind2 = IterImplNumber .intDigits [iter .buf [i ]];
394
400
if (ind2 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
395
401
iter .head = i ;
396
- return ind ;
402
+ return - ind ;
397
403
}
398
404
int ind3 = IterImplNumber .intDigits [iter .buf [++i ]];
399
405
if (ind3 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
400
406
iter .head = i ;
401
- return ind * 10 + ind2 ;
407
+ ind = ind * 10 + ind2 ;
408
+ return -ind ;
402
409
}
403
410
int ind4 = IterImplNumber .intDigits [iter .buf [++i ]];
404
411
if (ind4 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
405
412
iter .head = i ;
406
- return ind * 100 + ind2 * 10 + ind3 ;
413
+ ind = ind * 100 + ind2 * 10 + ind3 ;
414
+ return -ind ;
407
415
}
408
416
int ind5 = IterImplNumber .intDigits [iter .buf [++i ]];
409
417
if (ind5 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
410
418
iter .head = i ;
411
- return ind * 1000 + ind2 * 100 + ind3 * 10 + ind4 ;
419
+ ind = ind * 1000 + ind2 * 100 + ind3 * 10 + ind4 ;
420
+ return -ind ;
412
421
}
413
422
int ind6 = IterImplNumber .intDigits [iter .buf [++i ]];
414
423
if (ind6 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
415
424
iter .head = i ;
416
- return ind * 10000 + ind2 * 1000 + ind3 * 100 + ind4 * 10 + ind5 ;
425
+ ind = ind * 10000 + ind2 * 1000 + ind3 * 100 + ind4 * 10 + ind5 ;
426
+ return -ind ;
417
427
}
418
428
int ind7 = IterImplNumber .intDigits [iter .buf [++i ]];
419
429
if (ind7 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
420
430
iter .head = i ;
421
- return ind * 100000 + ind2 * 10000 + ind3 * 1000 + ind4 * 100 + ind5 * 10 + ind6 ;
431
+ ind = ind * 100000 + ind2 * 10000 + ind3 * 1000 + ind4 * 100 + ind5 * 10 + ind6 ;
432
+ return -ind ;
422
433
}
423
434
int ind8 = IterImplNumber .intDigits [iter .buf [++i ]];
424
435
if (ind8 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
425
436
iter .head = i ;
426
- return ind * 1000000 + ind2 * 100000 + ind3 * 10000 + ind4 * 1000 + ind5 * 100 + ind6 * 10 + ind7 ;
437
+ ind = ind * 1000000 + ind2 * 100000 + ind3 * 10000 + ind4 * 1000 + ind5 * 100 + ind6 * 10 + ind7 ;
438
+ return -ind ;
427
439
}
428
440
int ind9 = IterImplNumber .intDigits [iter .buf [++i ]];
429
441
ind = ind * 10000000 + ind2 * 1000000 + ind3 * 100000 + ind4 * 10000 + ind5 * 1000 + ind6 * 100 + ind7 * 10 + ind8 ;
430
442
iter .head = i ;
431
443
if (ind9 == IterImplNumber .INVALID_CHAR_FOR_NUMBER ) {
432
- return ind ;
444
+ return - ind ;
433
445
}
434
446
}
435
447
return IterImplForStreaming .readLongSlowPath (iter , ind );
436
448
}
437
449
438
- static final double readPositiveDouble (final JsonIterator iter ) throws IOException {
450
+ static final double readDouble (final JsonIterator iter ) throws IOException {
439
451
int oldHead = iter .head ;
440
452
try {
441
453
try {
442
- long value = IterImplNumber .readLong (iter ); // without the dot
454
+ long value = IterImplNumber .readLong (iter ); // without the dot & sign
443
455
if (iter .head == iter .tail ) {
444
456
return value ;
445
457
}
@@ -448,11 +460,14 @@ static final double readPositiveDouble(final JsonIterator iter) throws IOExcepti
448
460
iter .head ++;
449
461
int start = iter .head ;
450
462
c = iter .buf [iter .head ++];
451
- long decimalPart = readPositiveLong (iter , c );
463
+ long decimalPart = readLong (iter , c );
464
+ if (decimalPart == Long .MIN_VALUE ) {
465
+ return IterImplForStreaming .readDoubleSlowPath (iter );
466
+ }
467
+ decimalPart = -decimalPart ;
452
468
int decimalPlaces = iter .head - start ;
453
469
if (decimalPlaces > 0 && decimalPlaces < IterImplNumber .POW10 .length && (iter .head - oldHead ) < 10 ) {
454
- value = value * IterImplNumber .POW10 [decimalPlaces ] + decimalPart ;
455
- return value / (double ) IterImplNumber .POW10 [decimalPlaces ];
470
+ return value + (decimalPart / (double ) IterImplNumber .POW10 [decimalPlaces ]);
456
471
} else {
457
472
iter .head = oldHead ;
458
473
return IterImplForStreaming .readDoubleSlowPath (iter );
0 commit comments