File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -567,13 +567,16 @@ function caml_format_float(fmt, x) {
567567//Requires: caml_failwith, caml_jsbytes_of_string
568568function caml_float_of_string ( s ) {
569569 var res ;
570+ var r_float = / ^ * [ - + ] ? (?: \d * \. ? \d + | \d + \. ? \d * ) (?: [ e E ] [ - + ] ? \d + ) ? $ / ;
570571 s = caml_jsbytes_of_string ( s ) ;
571572 res = + s ;
572- if ( s . length > 0 && res === res ) return res ;
573+ //Fast path
574+ if ( ! Number . isNaN ( res ) && r_float . test ( s ) ) return res ;
573575 s = s . replace ( / _ / g, "" ) ;
574576 res = + s ;
575- if ( ( s . length > 0 && res === res ) || / ^ [ + - ] ? n a n $ / i. test ( s ) ) return res ;
576- var m = / ^ * ( [ + - ] ? ) 0 x ( [ 0 - 9 a - f ] + ) \. ? ( [ 0 - 9 a - f ] * ) ( p ( [ + - ] ? [ 0 - 9 ] + ) ) ? / i. exec ( s ) ;
577+ if ( ( ! Number . isNaN ( res ) && r_float . test ( s ) ) || / ^ [ + - ] ? n a n $ / i. test ( s ) )
578+ return res ;
579+ var m = / ^ * ( [ + - ] ? ) 0 x ( [ 0 - 9 a - f ] + ) \. ? ( [ 0 - 9 a - f ] * ) ( p ( [ + - ] ? [ 0 - 9 ] + ) ) ? $ / i. exec ( s ) ;
577580 // 1 2 3 5
578581 if ( m ) {
579582 var m3 = m [ 3 ] . replace ( / 0 + $ / , "" ) ;
You can’t perform that action at this time.
0 commit comments