summaryrefslogtreecommitdiff
path: root/src/lbaselib.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-29 21:40:55 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-29 22:07:08 +1100
commit370fd190c38242d152525ad3ae38104620c3359f (patch)
treefdb9baff8200b37dcb98410179fc34fa19794d1e /src/lbaselib.js
parent51c6728620d5c6095a7581acff5bbc689c7f7eec (diff)
downloadfengari-370fd190c38242d152525ad3ae38104620c3359f.tar.gz
fengari-370fd190c38242d152525ad3ae38104620c3359f.tar.bz2
fengari-370fd190c38242d152525ad3ae38104620c3359f.zip
src/lbaselib.js: Optimise b_str2int by using parseInt
Diffstat (limited to 'src/lbaselib.js')
-rw-r--r--src/lbaselib.js14
1 files changed, 3 insertions, 11 deletions
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<digits.length; si++) {
- let digit = /\d/.test(digits[si])
- ? (digits.charCodeAt(si) - '0'.charCodeAt(0))
- : (digits[si].toUpperCase().charCodeAt(0) - 'A'.charCodeAt(0) + 10);
- if (digit >= 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) {