summaryrefslogtreecommitdiff
path: root/src/lobject.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-06-01 17:57:10 +1000
committerdaurnimator <quae@daurnimator.com>2017-06-01 17:57:10 +1000
commit82694d3d46b6488982407de6218e5c7b768287cd (patch)
treefb8448daafe412899b46c35b35eeee4b0df98eb4 /src/lobject.js
parentcf46bc042fb475c9e2d21fc8782ede28d05054c2 (diff)
downloadfengari-82694d3d46b6488982407de6218e5c7b768287cd.tar.gz
fengari-82694d3d46b6488982407de6218e5c7b768287cd.tar.bz2
fengari-82694d3d46b6488982407de6218e5c7b768287cd.zip
src/lobject.js: Remove .slice operations from l_str2int
Diffstat (limited to 'src/lobject.js')
-rw-r--r--src/lobject.js28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 7c81045..7174ef6 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -446,36 +446,32 @@ const MAXBY10 = Math.floor(llimit.MAX_INT / 10);
const MAXLASTD = llimit.MAX_INT % 10;
const l_str2int = function(s) {
+ let i = 0;
let a = 0;
let empty = true;
let neg;
- while (ljstype.lisspace(s[0])) s = s.slice(1); /* skip initial spaces */
- neg = s[0] === char['-'];
-
- if (neg || s[0] === char['+'])
- s = s.slice(1);
-
- if (s[0] === char['0'] && (s[1] === char['x'] || s[1] === char['X'])) { /* hex? */
- s = s.slice(2); /* skip '0x' */
+ while (ljstype.lisspace(s[i])) i++; /* skip initial spaces */
+ if ((neg = (s[i] === char['-']))) i++;
+ else if (s[i] === char['+']) i++;
+ if (s[i] === char['0'] && (s[i+1] === char['x'] || s[i+1] === char['X'])) { /* hex? */
+ i += 2; /* skip '0x' */
- for (; ljstype.lisxdigit(s[0]); s = s.slice(1)) {
- a = (a * 16 + luaO_hexavalue(s[0]))|0;
+ for (; ljstype.lisxdigit(s[i]); i++) {
+ a = (a * 16 + luaO_hexavalue(s[i]))|0;
empty = false;
}
} else { /* decimal */
- for (; ljstype.lisdigit(s[0]); s = s.slice(1)) {
- let d = s[0] - char['0'];
+ for (; ljstype.lisdigit(s[i]); i++) {
+ let d = s[i] - char['0'];
if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */
return null; /* do not accept it (as integer) */
a = (a * 10 + d)|0;
empty = false;
}
}
-
- while (ljstype.lisspace(s[0])) s = s.slice(1); /* skip trailing spaces */
-
- if (empty || (s.length !== 0)) return null; /* something wrong in the numeral */
+ while (ljstype.lisspace(s[i])) i++; /* skip trailing spaces */
+ if (empty || (i !== s.length)) return null; /* something wrong in the numeral */
else {
return (neg ? -a : a)|0;
}