aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-07 04:39:00 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-07 04:39:00 +1100
commite0089c7adee8e313f7ff7b5d84ff0ea892c05287 (patch)
tree7b05c3cfafd0c782bc6a8d512a8c75000a6282d1
parentef0784b2982e65af05982d8e1e18ef1d45ea96ad (diff)
downloadfengari-e0089c7adee8e313f7ff7b5d84ff0ea892c05287.tar.gz
fengari-e0089c7adee8e313f7ff7b5d84ff0ea892c05287.tar.bz2
fengari-e0089c7adee8e313f7ff7b5d84ff0ea892c05287.zip
src/lobject.js: Optimise l_str2d + removing use of spread operator (IE compat)
-rw-r--r--src/lobject.js22
1 files changed, 15 insertions, 7 deletions
diff --git a/src/lobject.js b/src/lobject.js
index 824fc88..641473e 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -448,17 +448,25 @@ const l_str2dloc = function(s, mode) {
return (result.i === s.length || s[result.i] === 0) ? result : null; /* OK if no trailing characters */
};
+const SIGILS = [char["."], char["x"], char["X"], char["n"], char["N"]];
+const modes = {[char["."]]: ".", [char["x"]]: "x", [char["X"]]: "x", [char["n"]]: "n", [char["N"]]: "n"};
const l_str2d = function(s) {
- let pidx = /[.xXnN]/g.exec(String.fromCharCode(...s));
- pidx = pidx ? pidx.index : null;
- let pmode = pidx ? s[pidx] : null;
- let mode = pmode ? String.fromCharCode(pmode).toLowerCase() : 0;
+ let l = s.length;
+ let pmode = 0;
+ for (let i=0; i<l; i++) {
+ let v = s[i];
+ if (SIGILS.indexOf(v) !== -1) {
+ pmode = v;
+ break;
+ }
+ }
+ let mode = modes[pmode];
if (mode === 'n') /* reject 'inf' and 'nan' */
return null;
let end = l_str2dloc(s, mode); /* try to convert */
- if (end === null) { /* failed? may be a different locale */
- // throw new Error("Locale not available to handle number"); // TODO
- }
+ // if (end === null) { /* failed? may be a different locale */
+ // throw new Error("Locale not available to handle number"); // TODO
+ // }
return end;
};