Browse Source

A faster / more stable parseInt (#7461)

Jeff Ward 6 years ago
parent
commit
b75fc89d72
1 changed files with 1 additions and 4 deletions
  1. 1 4
      std/js/_std/Std.hx

+ 1 - 4
std/js/_std/Std.hx

@@ -43,10 +43,7 @@ import js.Boot;
 
 	@:pure
 	public static function parseInt( x : String ) : Null<Int> {
-		var v = untyped __js__("parseInt")(x, 10);
-		// parse again if hexadecimal
-		if( v == 0 && (x.charCodeAt(1) == 'x'.code || x.charCodeAt(1) == 'X'.code) )
-			v = untyped __js__("parseInt")(x);
+		var v = untyped __js__('parseInt({0}, {0} && {0}[0]=="0" && ({0}[1]=="x" || {0}[1]=="X") ? 16 : 10)', x);
 		if( untyped __js__("isNaN")(v) )
 			return null;
 		return cast v;