Skip to content

Commit 935e8b1

Browse files
committed
Use only Map for caching, remove keyed fallback
1 parent c43d31d commit 935e8b1

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

src/index.mjs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,15 @@
1414
import { MINI } from './constants.mjs';
1515
import { build, evaluate } from './build.mjs';
1616

17-
const getCacheMap = (statics) => {
18-
let tpl = CACHE.get(statics);
19-
if (!tpl) {
20-
CACHE.set(statics, tpl = build(statics));
21-
}
22-
return tpl;
23-
};
24-
25-
const getCacheKeyed = (statics) => {
26-
let key = '';
27-
for (let i = 0; i < statics.length; i++) {
28-
key += statics[i].length + '-' + statics[i];
29-
}
30-
return CACHE[key] || (CACHE[key] = build(statics));
31-
};
32-
33-
const USE_MAP = !MINI && typeof Map === 'function';
34-
const CACHE = USE_MAP ? new Map() : {};
35-
const getCache = USE_MAP ? getCacheMap : getCacheKeyed;
17+
const CACHE = new Map();
3618

3719
const cached = function(statics) {
38-
const res = evaluate(this, getCache(statics), arguments, []);
39-
return res.length > 1 ? res : res[0];
20+
let tmp = CACHE.get(statics);
21+
if (!tmp) {
22+
CACHE.set(statics, tmp = build(statics));
23+
}
24+
tmp = evaluate(this, tmp, arguments, []);
25+
return tmp.length > 1 ? tmp : tmp[0];
4026
};
4127

4228
export default MINI ? build : cached;

0 commit comments

Comments
 (0)