From 9920092649e5ac3eeef6404d7dc783301bf4b45a Mon Sep 17 00:00:00 2001 From: jmoenig Date: Sat, 27 Jun 2020 16:34:12 +0200 Subject: [PATCH] cached NONNUMBERS cases in order to speed up snapEquals() some --- src/threads.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/threads.js b/src/threads.js index 9ce56962..889c65fc 100644 --- a/src/threads.js +++ b/src/threads.js @@ -70,6 +70,19 @@ var Variable; var VariableFrame; var JSCompiler; +const NONNUMBERS = [true, false, '']; + +(function () { + // "zum Schneckengang verdorben, was Adlerflug geworden wäre" + // collecting edge-cases that somebody complained about + // on Github. Folks, take it easy and keep it fun, okay? + // Shit like this is patently ugly and slows Snap down. Tnx! + for (var i = 9; i <= 13; i += 1) { + NONNUMBERS.push(String.fromCharCode(i)); + } + NONNUMBERS.push(String.fromCharCode(160)); +})(); + function snapEquals(a, b) { if (a instanceof List || (b instanceof List)) { if (a instanceof List && (b instanceof List)) { @@ -79,22 +92,11 @@ function snapEquals(a, b) { } var x = +a, - y = +b, - i, - specials = [true, false, '']; - - // "zum Schneckengang verdorben, was Adlerflug geworden wäre" - // collecting edge-cases that somebody complained about - // on Github. Folks, take it easy and keep it fun, okay? - // Shit like this is patently ugly and slows Snap down. Tnx! - for (i = 9; i <= 13; i += 1) { - specials.push(String.fromCharCode(i)); - } - specials.push(String.fromCharCode(160)); + y = +b; // check for special values before coercing to numbers if (isNaN(x) || isNaN(y) || - [a, b].some(any => contains(specials, any) || + [a, b].some(any => contains(NONNUMBERS, any) || (isString(any) && (any.indexOf(' ') > -1))) ) { x = a;