Skip to content

Commit fa4f822

Browse files
Revert "Memoize entity encoding"
This reverts commit f5bae9e. Because we cannot forsee the length and amount of strings we need to be more careful about keeping them around as memory consumption can grow unbounded. In the future we should check if we can use a limited cache, only cache attributes or something else. WeakMaps unfortunately won't help as they cannot be used with primitives as cache key.
1 parent b6f6fc7 commit fa4f822

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

src/util.js

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/**
2-
* @template T
3-
* @param {T} fn
4-
* @returns {T}
5-
*/
6-
function memoize(fn) {
7-
const cache = new Map();
8-
return (arg) => {
9-
let res = cache.get(arg);
10-
if (!res) {
11-
res = fn(arg);
12-
cache.set(arg, res);
13-
}
14-
return res;
15-
};
16-
}
17-
181
// DOM properties that should NOT have "px" added when numeric
192
export const IS_NON_DIMENSIONAL = /acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|^--/i;
203

@@ -26,15 +9,10 @@ const tagsToReplace = {
269
'"': '"'
2710
};
2811
const replaceTag = (tag) => tagsToReplace[tag] || tag;
29-
30-
/**
31-
* @param {any} s
32-
* @returns {string}
33-
*/
34-
export const encodeEntities = memoize((s) => {
12+
export function encodeEntities(s) {
3513
if (typeof s !== 'string') s = String(s);
3614
return s.replace(HTML_ENTITY_REG, replaceTag);
37-
});
15+
}
3816

3917
export let indent = (s, char) =>
4018
String(s).replace(/(\n+)/g, '$1' + (char || '\t'));

0 commit comments

Comments
 (0)