From 75fbb1565cb9046b83c32df5f4211a62ef355067 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 13 Feb 2020 20:26:48 -0500 Subject: Use Map for audioGetFromSources's cache parameter --- ext/mixed/js/audio.js | 9 ++++++--- ext/mixed/js/display.js | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/audio.js b/ext/mixed/js/audio.js index 76a3e7da..47db5c75 100644 --- a/ext/mixed/js/audio.js +++ b/ext/mixed/js/audio.js @@ -114,8 +114,11 @@ function audioGetFromUrl(url, willDownload) { async function audioGetFromSources(expression, sources, optionsContext, willDownload, cache=null) { const key = `${expression.expression}:${expression.reading}`; - if (cache !== null && hasOwn(cache, expression)) { - return cache[key]; + if (cache !== null) { + const cacheValue = cache.get(expression); + if (typeof cacheValue !== 'undefined') { + return cacheValue; + } } for (let i = 0, ii = sources.length; i < ii; ++i) { @@ -133,7 +136,7 @@ async function audioGetFromSources(expression, sources, optionsContext, willDown } const result = {audio, url, source}; if (cache !== null) { - cache[key] = result; + cache.set(key, result); } return result; } catch (e) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index b18e275d..5b868df3 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -32,7 +32,7 @@ class Display { this.index = 0; this.audioPlaying = null; this.audioFallback = null; - this.audioCache = {}; + this.audioCache = new Map(); this.styleNode = null; this.eventListeners = []; -- cgit v1.2.3