From 370fd190c38242d152525ad3ae38104620c3359f Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 29 Jan 2018 21:40:55 +1100 Subject: src/lbaselib.js: Optimise b_str2int by using parseInt --- src/lbaselib.js | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/lbaselib.js b/src/lbaselib.js index e14d34d..f5af541 100644 --- a/src/lbaselib.js +++ b/src/lbaselib.js @@ -274,17 +274,9 @@ const b_str2int = function(s, base) { } let r = /^[\t\v\f \n\r]*([+-]?)0*([0-9A-Za-z]+)[\t\v\f \n\r]*$/.exec(s); if (!r) return null; - let neg = r[1] === "-"; - let digits = r[2]; - let n = 0; - for (let si=0; si= base) return null; /* invalid numeral */ - n = ((n * base)|0) + digit; - } - return (neg ? -n : n)|0; + let v = parseInt(r[1]+r[2], base); + if (isNaN(v)) return null; + return v|0; }; const luaB_tonumber = function(L) { -- cgit v1.2.3-70-g09d2