diff --git a/src/main/java/com/fasterxml/jackson/core/io/doubleparser/FastDoubleParser.java b/src/main/java/com/fasterxml/jackson/core/io/doubleparser/FastDoubleParser.java index 9a93f6f0a8..d6161509fe 100644 --- a/src/main/java/com/fasterxml/jackson/core/io/doubleparser/FastDoubleParser.java +++ b/src/main/java/com/fasterxml/jackson/core/io/doubleparser/FastDoubleParser.java @@ -15,6 +15,8 @@ */ public class FastDoubleParser { + private static final DoubleBitsFromCharArray CHAR_ARRAY_PARSER = new DoubleBitsFromCharArray(); + private static final DoubleBitsFromCharSequence CHAR_SEQ_PARSER = new DoubleBitsFromCharSequence(); /** * Don't let anyone instantiate this class. @@ -47,7 +49,7 @@ public static double parseDouble(CharSequence str) throws NumberFormatException * @throws NumberFormatException if the string can not be parsed */ public static double parseDouble(CharSequence str, int offset, int length) throws NumberFormatException { - long bitPattern = new DoubleBitsFromCharSequence().parseFloatingPointLiteral(str, offset, length); + long bitPattern = CHAR_SEQ_PARSER.parseFloatingPointLiteral(str, offset, length); if (bitPattern == AbstractFloatValueParser.PARSE_ERROR) { throw new NumberFormatException("Illegal input"); } @@ -79,7 +81,7 @@ public static double parseDouble(char[] str) throws NumberFormatException { * @throws NumberFormatException if the string can not be parsed */ public static double parseDouble(char[] str, int offset, int length) throws NumberFormatException { - long bitPattern = new DoubleBitsFromCharArray().parseFloatingPointLiteral(str, offset, length); + long bitPattern = CHAR_ARRAY_PARSER.parseFloatingPointLiteral(str, offset, length); if (bitPattern == AbstractFloatValueParser.PARSE_ERROR) { throw new NumberFormatException("Illegal input"); } @@ -109,7 +111,7 @@ public static double parseDouble(char[] str, int offset, int length) throws Numb * otherwise, {@code -1L}. */ public static long parseDoubleBits(CharSequence str, int offset, int length) { - return new DoubleBitsFromCharSequence().parseFloatingPointLiteral(str, offset, length); + return CHAR_SEQ_PARSER.parseFloatingPointLiteral(str, offset, length); } /** @@ -128,6 +130,6 @@ public static long parseDoubleBits(CharSequence str, int offset, int length) { * otherwise, {@code -1L}. */ public static long parseDoubleBits(char[] str, int offset, int length) { - return new DoubleBitsFromCharArray().parseFloatingPointLiteral(str, offset, length); + return CHAR_ARRAY_PARSER.parseFloatingPointLiteral(str, offset, length); } } \ No newline at end of file diff --git a/src/main/java/com/fasterxml/jackson/core/io/doubleparser/FastFloatParser.java b/src/main/java/com/fasterxml/jackson/core/io/doubleparser/FastFloatParser.java index 429d4abc77..90f6d54e33 100644 --- a/src/main/java/com/fasterxml/jackson/core/io/doubleparser/FastFloatParser.java +++ b/src/main/java/com/fasterxml/jackson/core/io/doubleparser/FastFloatParser.java @@ -15,6 +15,9 @@ */ public class FastFloatParser { + private static final FloatBitsFromCharArray CHAR_ARRAY_PARSER = new FloatBitsFromCharArray(); + private static final FloatBitsFromCharSequence CHAR_SEQ_PARSER = new FloatBitsFromCharSequence(); + /** * Don't let anyone instantiate this class. */ @@ -46,7 +49,7 @@ public static float parseFloat(CharSequence str) throws NumberFormatException { * @throws NumberFormatException if the string can not be parsed */ public static float parseFloat(CharSequence str, int offset, int length) throws NumberFormatException { - long bitPattern = new FloatBitsFromCharSequence().parseFloatingPointLiteral(str, offset, length); + long bitPattern = CHAR_SEQ_PARSER.parseFloatingPointLiteral(str, offset, length); if (bitPattern == AbstractFloatValueParser.PARSE_ERROR) { throw new NumberFormatException("Illegal input"); } @@ -78,7 +81,7 @@ public static float parseFloat(char[] str) throws NumberFormatException { * @throws NumberFormatException if the string can not be parsed */ public static float parseFloat(char[] str, int offset, int length) throws NumberFormatException { - long bitPattern = new FloatBitsFromCharArray().parseFloatingPointLiteral(str, offset, length); + long bitPattern = CHAR_ARRAY_PARSER.parseFloatingPointLiteral(str, offset, length); if (bitPattern == AbstractFloatValueParser.PARSE_ERROR) { throw new NumberFormatException("Illegal input"); } @@ -108,7 +111,7 @@ public static float parseFloat(char[] str, int offset, int length) throws Number * otherwise, {@code -1L}. */ public static long parseFloatBits(CharSequence str, int offset, int length) { - return new FloatBitsFromCharSequence().parseFloatingPointLiteral(str, offset, length); + return CHAR_SEQ_PARSER.parseFloatingPointLiteral(str, offset, length); } /** @@ -127,6 +130,6 @@ public static long parseFloatBits(CharSequence str, int offset, int length) { * otherwise, {@code -1L}. */ public static long parseFloatBits(char[] str, int offset, int length) { - return new FloatBitsFromCharArray().parseFloatingPointLiteral(str, offset, length); + return CHAR_ARRAY_PARSER.parseFloatingPointLiteral(str, offset, length); } } \ No newline at end of file