1515 */
1616public class FastDoubleParser {
1717
18+ private static final DoubleBitsFromCharArray CHAR_ARRAY_PARSER = new DoubleBitsFromCharArray ();
19+ private static final DoubleBitsFromCharSequence CHAR_SEQ_PARSER = new DoubleBitsFromCharSequence ();
1820
1921 /**
2022 * Don't let anyone instantiate this class.
@@ -47,7 +49,7 @@ public static double parseDouble(CharSequence str) throws NumberFormatException
4749 * @throws NumberFormatException if the string can not be parsed
4850 */
4951 public static double parseDouble (CharSequence str , int offset , int length ) throws NumberFormatException {
50- long bitPattern = new DoubleBitsFromCharSequence () .parseFloatingPointLiteral (str , offset , length );
52+ long bitPattern = CHAR_SEQ_PARSER .parseFloatingPointLiteral (str , offset , length );
5153 if (bitPattern == AbstractFloatValueParser .PARSE_ERROR ) {
5254 throw new NumberFormatException ("Illegal input" );
5355 }
@@ -79,7 +81,7 @@ public static double parseDouble(char[] str) throws NumberFormatException {
7981 * @throws NumberFormatException if the string can not be parsed
8082 */
8183 public static double parseDouble (char [] str , int offset , int length ) throws NumberFormatException {
82- long bitPattern = new DoubleBitsFromCharArray () .parseFloatingPointLiteral (str , offset , length );
84+ long bitPattern = CHAR_ARRAY_PARSER .parseFloatingPointLiteral (str , offset , length );
8385 if (bitPattern == AbstractFloatValueParser .PARSE_ERROR ) {
8486 throw new NumberFormatException ("Illegal input" );
8587 }
@@ -109,7 +111,7 @@ public static double parseDouble(char[] str, int offset, int length) throws Numb
109111 * otherwise, {@code -1L}.
110112 */
111113 public static long parseDoubleBits (CharSequence str , int offset , int length ) {
112- return new DoubleBitsFromCharSequence () .parseFloatingPointLiteral (str , offset , length );
114+ return CHAR_SEQ_PARSER .parseFloatingPointLiteral (str , offset , length );
113115 }
114116
115117 /**
@@ -128,6 +130,6 @@ public static long parseDoubleBits(CharSequence str, int offset, int length) {
128130 * otherwise, {@code -1L}.
129131 */
130132 public static long parseDoubleBits (char [] str , int offset , int length ) {
131- return new DoubleBitsFromCharArray () .parseFloatingPointLiteral (str , offset , length );
133+ return CHAR_ARRAY_PARSER .parseFloatingPointLiteral (str , offset , length );
132134 }
133135}
0 commit comments