summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2018-01-07 02:07:17 +1100
committerdaurnimator <quae@daurnimator.com>2018-01-07 02:07:17 +1100
commit6ffe07fc5d16ee9acdcd6651d433ce13b193cd15 (patch)
tree11b7d6ff7e64b5b52bb0e68eb14224cfc092e7da
parenta80d704ceb4e7d85dc54a9c3706d6ffa7bf2412f (diff)
downloadfengari-6ffe07fc5d16ee9acdcd6651d433ce13b193cd15.tar.gz
fengari-6ffe07fc5d16ee9acdcd6651d433ce13b193cd15.tar.bz2
fengari-6ffe07fc5d16ee9acdcd6651d433ce13b193cd15.zip
TypedArray.toString() doesn't return a unique string in some browsers
e.g. IE11 Instead iterate over string contents and manually build hash. I have *not* tested this for performance. An alternative option is to use Array.prototype.join.call
-rw-r--r--src/defs.js9
-rw-r--r--src/lstring.js6
2 files changed, 13 insertions, 2 deletions
diff --git a/src/defs.js b/src/defs.js
index b96dcf5..c0b3bda 100644
--- a/src/defs.js
+++ b/src/defs.js
@@ -159,7 +159,14 @@ const is_luastring = function(s) {
/* test two lua strings for equality */
const luastring_eq = function(a, b) {
- return a === b || (a.length === b.length && a.toString() === b.toString());
+ if (a !== b) {
+ let len = a.length;
+ if (len !== b.length) return false;
+ /* XXX: Should this be a constant time algorithm? */
+ for (let i=0; i<len; i++)
+ if (a[i] !== b[i]) return false;
+ }
+ return true;
};
const to_jsstring = function(value, from, to) {
diff --git a/src/lstring.js b/src/lstring.js
index 84754f0..d65fc6a 100644
--- a/src/lstring.js
+++ b/src/lstring.js
@@ -31,7 +31,11 @@ const luaS_eqlngstr = function(a, b) {
make sure this doesn't conflict with any of the anti-collision strategies in ltable */
const luaS_hash = function(str) {
assert(defs.is_luastring(str));
- return '|'+str.toString();
+ let len = str.length;
+ let s = "|";
+ for (let i=0; i<len; i++)
+ s += str[i].toString(16);
+ return s;
};
const luaS_hashlongstr = function(ts) {