js+execute: Remove listGetFast

The ?? operator is used instead.
Older browsers now simply won't get this optimization.
This commit is contained in:
Thomas Weber committed 2020-09-09 22:03:24 -05:00
1 parent 36ee6f65de
commit 94f09e10b2
2 files changed
+2 -18

No files matched your search

-13
View File
@@ -373,19 +373,6 @@ const listGet = (list, idx) => {
return list[index];
};
/**
* listGet() optimized for number arguments.
* @param {Array} list The list
* @param {number} idx The 1-indexed index in the list.
* @returns The list item, otherwise empty string if it does not exist.
*/
const listGetFast = (list, idx) => {
if (idx < 1 || idx > list.length) {
return '';
}
return list[Math.floor(idx) - 1];
};
/**
* Replace a value in a list.
* @param {import('../engine/variable')} list The list
+2 -5
View File
@@ -216,11 +216,8 @@ class JSGenerator {
return new TypedInput(`listContents(${this.referenceVariable(node.list)})`, TYPE_STRING);
case 'list.get': {
const index = this.descendInput(node.index);
if (index.isAlwaysNumber()) {
if (environment.supportsNullishCoalescing) {
return new TypedInput(`(${this.referenceVariable(node.list)}.value[Math.floor(${index.asNumber()}) - 1] ?? "")`, TYPE_UNKNOWN);
}
return new TypedInput(`listGetFast(${this.referenceVariable(node.list)}.value, ${index.asNumber()})`, TYPE_UNKNOWN);
if (environment.supportsNullishCoalescing && index.isAlwaysNumber()) {
return new TypedInput(`(${this.referenceVariable(node.list)}.value[Math.floor(${index.asNumber()}) - 1] ?? "")`, TYPE_UNKNOWN);
}
return new TypedInput(`listGet(${this.referenceVariable(node.list)}.value, ${index.asUnknown()})`, TYPE_UNKNOWN);
}