Use Map for audioGetFromSources's cache parameter
This commit is contained in:
parent
0e6b75438a
commit
75fbb1565c
@ -114,8 +114,11 @@ function audioGetFromUrl(url, willDownload) {
|
|||||||
|
|
||||||
async function audioGetFromSources(expression, sources, optionsContext, willDownload, cache=null) {
|
async function audioGetFromSources(expression, sources, optionsContext, willDownload, cache=null) {
|
||||||
const key = `${expression.expression}:${expression.reading}`;
|
const key = `${expression.expression}:${expression.reading}`;
|
||||||
if (cache !== null && hasOwn(cache, expression)) {
|
if (cache !== null) {
|
||||||
return cache[key];
|
const cacheValue = cache.get(expression);
|
||||||
|
if (typeof cacheValue !== 'undefined') {
|
||||||
|
return cacheValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0, ii = sources.length; i < ii; ++i) {
|
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};
|
const result = {audio, url, source};
|
||||||
if (cache !== null) {
|
if (cache !== null) {
|
||||||
cache[key] = result;
|
cache.set(key, result);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -32,7 +32,7 @@ class Display {
|
|||||||
this.index = 0;
|
this.index = 0;
|
||||||
this.audioPlaying = null;
|
this.audioPlaying = null;
|
||||||
this.audioFallback = null;
|
this.audioFallback = null;
|
||||||
this.audioCache = {};
|
this.audioCache = new Map();
|
||||||
this.styleNode = null;
|
this.styleNode = null;
|
||||||
|
|
||||||
this.eventListeners = [];
|
this.eventListeners = [];
|
||||||
|
Loading…
Reference in New Issue
Block a user