Skip to content

Commit 3fc89cd

Browse files
committed
Add release notes wrt #865, minor post-merge tweaks
1 parent 3188b19 commit 3fc89cd

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

release-notes/CREDITS-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ Philippe Marschall (marschall@github)
196196
(2.10.0)
197197
* Contributed #798: Avoid copy when parsing `BigDecimal`
198198
(2.14.0)
199+
* Contributed #865: Optimize parsing 19 digit longs
200+
(2.15.0)
199201

200202
David Nault (dnault@github)
201203
* Reported #531: Non-blocking parser reports incorrect locations when fed with

release-notes/VERSION-2.x

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ JSON library.
2121
#851: Add `StreamReadFeature.USE_FAST_BIG_DECIMAL_PARSER` to enable
2222
faster `BigDecimal`, `BigInteger` parsing
2323
(contributed by @pjfanning)
24+
#865: Optimize parsing 19 digit longs
25+
(contributed by Phillipe M)
2426
- Build uses package type "jar" but still produces valid OSGi bundle
2527
(changed needed to keep class timestamps with Reproducible Build)
2628

src/main/java/com/fasterxml/jackson/core/base/ParserBase.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,19 @@ protected void _parseNumericValue(int expType) throws IOException
883883
_numTypesValid = NR_LONG;
884884
return;
885885
}
886+
// For [core#865]: handle remaining 19-char cases as well
887+
if (len == 19) {
888+
char[] buf = _textBuffer.getTextBuffer();
889+
int offset = _textBuffer.getTextOffset();
890+
if (_numberNegative) {
891+
++offset;
892+
}
893+
if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
894+
_numberLong = NumberInput.parseLong19(buf, offset, _numberNegative);
895+
_numTypesValid = NR_LONG;
896+
return;
897+
}
898+
}
886899
_parseSlowInt(expType);
887900
return;
888901
}
@@ -956,35 +969,22 @@ private void _parseSlowFloat(int expType) throws IOException
956969

957970
private void _parseSlowInt(int expType) throws IOException
958971
{
972+
final String numStr = _textBuffer.contentsAsString();
959973
try {
960-
int len = _intLength;
961-
char[] buf = _textBuffer.getTextBuffer();
962-
int offset = _textBuffer.getTextOffset();
963-
if (_numberNegative) {
964-
++offset;
974+
// 16-Oct-2018, tatu: Need to catch "too big" early due to [jackson-core#488]
975+
if ((expType == NR_INT) || (expType == NR_LONG)) {
976+
_reportTooLongIntegral(expType, numStr);
965977
}
966-
// Some long cases still...
967-
if (NumberInput.inLongRange(buf, offset, len, _numberNegative)) {
968-
_numberLong = NumberInput.parseLong19(buf, offset, _numberNegative);
969-
_numTypesValid = NR_LONG;
978+
if ((expType == NR_DOUBLE) || (expType == NR_FLOAT)) {
979+
_numberDouble = NumberInput.parseDouble(numStr, isEnabled(Feature.USE_FAST_DOUBLE_PARSER));
980+
_numTypesValid = NR_DOUBLE;
970981
} else {
971-
String numStr = _textBuffer.contentsAsString();
972-
// 16-Oct-2018, tatu: Need to catch "too big" early due to [jackson-core#488]
973-
if ((expType == NR_INT) || (expType == NR_LONG)) {
974-
_reportTooLongIntegral(expType, numStr);
975-
}
976-
if ((expType == NR_DOUBLE) || (expType == NR_FLOAT)) {
977-
_numberDouble = NumberInput.parseDouble(numStr, isEnabled(Feature.USE_FAST_DOUBLE_PARSER));
978-
_numTypesValid = NR_DOUBLE;
979-
} else {
980-
// nope, need the heavy guns... (rare case) - since Jackson v2.14, BigInteger parsing is lazy
981-
_numberBigInt = null;
982-
_numberString = numStr;
983-
_numTypesValid = NR_BIGINT;
984-
}
982+
// nope, need the heavy guns... (rare case) - since Jackson v2.14, BigInteger parsing is lazy
983+
_numberBigInt = null;
984+
_numberString = numStr;
985+
_numTypesValid = NR_BIGINT;
985986
}
986987
} catch (NumberFormatException nex) {
987-
String numStr = _textBuffer.contentsAsString();
988988
// Can this ever occur? Due to overflow, maybe?
989989
_wrapError("Malformed numeric value ("+_longNumberDesc(numStr)+")", nex);
990990
}

src/main/java/com/fasterxml/jackson/core/io/NumberInput.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,12 @@ public static long parseLong(char[] ch, int off, int len)
167167
* @param off Offset of the first digit character in buffer
168168
* @param negative Whether original number had a minus sign
169169
* @return Decoded {@code long} value
170+
*
171+
* @since 2.15.0
170172
*/
171173
public static long parseLong19(char[] ch, int off, boolean negative)
172174
{
173-
// Note: caller must ensure length is [10, 18]
175+
// Note: caller must ensure length is 19
174176
long num = 0L;
175177
for (int i = 0; i < 19; i++) {
176178
char c = ch[off + i];

0 commit comments

Comments
 (0)