A platform for community discussion. Free, open, simple.
FIX: Use Map instead of Object for caching (#14887)
Bianca Nenciu32a174d88378
diff --git a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.jsindex b03f30fa7bd..34384a54a29 100644--- a/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js+++ b/app/assets/javascripts/discourse/tests/unit/lib/pretty-text-test.js@@ -1689,6 +1689,7 @@ var bar = 'bar';};assert.cookedOptions("test fun funny", opts, "<p>test times funny</p>");+ assert.cookedOptions("constructor", opts, "<p>constructor</p>");});test("watched words link", function (assert) {diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.jsindex d82e13f8d03..7c09bf1c35c 100644--- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js+++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/watched-words.js@@ -73,7 +73,7 @@ export function setup(helper) {return;}- const cache = {};+ const cache = new Map();md.core.ruler.push("watched-words", (state) => {for (let j = 0, l = state.tokens.length; j < l; j++) {@@ -153,8 +153,14 @@ export function setup(helper) {if (currentToken.type === "text") {const text = currentToken.content;- const matches = (cache[text] =- cache[text] || findAllMatches(text, matchers));++ let matches;+ if (cache.has(text)) {+ matches = cache.get(text);+ } else {+ matches = findAllMatches(text, matchers);+ cache.set(text, matches);+ }// Now split string to nodesconst nodes = [];