From 1a5cf6fef4de9152bfecf384d7c95b08967a2783 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 19 Sep 2024 21:02:26 -0400 Subject: [PATCH] perf: improve get_setters cache (#13343) --- .../svelte/src/internal/client/dom/elements/attributes.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/svelte/src/internal/client/dom/elements/attributes.js b/packages/svelte/src/internal/client/dom/elements/attributes.js index 9f92c59d15..ee6525d8d5 100644 --- a/packages/svelte/src/internal/client/dom/elements/attributes.js +++ b/packages/svelte/src/internal/client/dom/elements/attributes.js @@ -184,8 +184,7 @@ export function set_attributes( next.class = next.class ? next.class + ' ' + css_hash : css_hash; } - var setters = setters_cache.get(element.nodeName); - if (!setters) setters_cache.set(element.nodeName, (setters = get_setters(element))); + var setters = get_setters(element); // @ts-expect-error var attributes = /** @type {Record} **/ (element.__attributes ??= {}); @@ -356,8 +355,9 @@ var setters_cache = new Map(); /** @param {Element} element */ function get_setters(element) { - /** @type {string[]} */ - var setters = []; + var setters = setters_cache.get(element.nodeName); + if (setters) return setters; + setters_cache.set(element.nodeName, (setters = [])); var descriptors; var proto = get_prototype_of(element);