chore: improve the performance of set_text for single expressions (#12893)

pull/12897/head
Dominic Gannaway 3 months ago committed by GitHub
parent 47e8ad7619
commit 7eabce8c96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
chore: improve the performance of set_text for single expressions

@ -64,6 +64,10 @@ export function build_template_literal(values, visit, state) {
)
);
expressions.push(b.call('$.get', id));
} else if (values.length === 1) {
// If we have a single expression, then pass that in directly to possibly avoid doing
// extra work in the template_effect (instead we do the work in set_text).
return { value: visit(node.expression, state), has_state, has_call };
} else {
expressions.push(b.logical('??', visit(node.expression, state), b.literal('')));
}

@ -51,7 +51,8 @@ export function set_text(text, value) {
// @ts-expect-error
if (value !== (text.__t ??= text.nodeValue)) {
// @ts-expect-error
text.nodeValue = text.__t = value;
text.__t = value;
text.nodeValue = value == null ? '' : value + '';
}
}

@ -2,4 +2,4 @@
const { foo } = x();
</script>
{#each foo as f}{/each}
{#each foo as f}{/each}

@ -11,11 +11,11 @@ export default function Purity($$anchor) {
var fragment = root();
var p = $.first_child(fragment);
p.textContent = `${Math.max(min, Math.min(max, number)) ?? ""}`;
p.textContent = Math.max(min, Math.min(max, number));
var p_1 = $.sibling($.sibling(p, true));
p_1.textContent = `${location.href ?? ""}`;
p_1.textContent = location.href;
var node = $.sibling($.sibling(p_1, true));

Loading…
Cancel
Save