pull/18732/merge
Utkarsh Yadav 1 day ago committed by GitHub
commit 65048f35e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
perf: use `Set` for rest-prop exclude lists in server, legacy, and shared utils

@ -450,14 +450,13 @@ export function client_component(analysis, options) {
for (const [name, binding] of analysis.instance.scope.declarations) { for (const [name, binding] of analysis.instance.scope.declarations) {
if (binding.kind === 'bindable_prop') named_props.push(binding.prop_alias ?? name); if (binding.kind === 'bindable_prop') named_props.push(binding.prop_alias ?? name);
} }
component_block.body.unshift( component_block.body.unshift(
b.const( b.const(
'$$restProps', '$$restProps',
b.call( b.call(
'$.legacy_rest_props', '$.legacy_rest_props',
b.id('$$sanitized_props'), b.id('$$sanitized_props'),
b.array(named_props.map((name) => b.literal(name))) b.new('Set', b.array(named_props.map((name) => b.literal(name))))
) )
) )
); );
@ -477,7 +476,7 @@ export function client_component(analysis, options) {
component_block.body.unshift( component_block.body.unshift(
b.const( b.const(
'$$sanitized_props', '$$sanitized_props',
b.call('$.legacy_rest_props', b.id('$$props'), b.array(to_remove)) b.call('$.legacy_rest_props', b.id('$$props'), b.new('Set', b.array(to_remove)))
) )
); );
} }

@ -288,14 +288,13 @@ export function server_component(analysis, options) {
for (const [name, binding] of analysis.instance.scope.declarations) { for (const [name, binding] of analysis.instance.scope.declarations) {
if (binding.kind === 'bindable_prop') named_props.push(binding.prop_alias ?? name); if (binding.kind === 'bindable_prop') named_props.push(binding.prop_alias ?? name);
} }
component_block.body.unshift( component_block.body.unshift(
b.const( b.const(
'$$restProps', '$$restProps',
b.call( b.call(
'$.rest_props', '$.rest_props',
b.id('$$sanitized_props'), b.id('$$sanitized_props'),
b.array(named_props.map((name) => b.literal(name))) b.new('Set', b.array(named_props.map((name) => b.literal(name))))
) )
) )
); );

@ -297,7 +297,11 @@ function _extract_paths(paths, inserts, param, expression, update_expression, ha
} }
} }
const rest_expression = b.call('$.exclude_from_object', expression, b.array(props)); const rest_expression = b.call(
'$.exclude_from_object',
expression,
b.new('Set', b.array(props))
);
if (prop.argument.type === 'Identifier') { if (prop.argument.type === 'Identifier') {
paths.push({ paths.push({

@ -96,11 +96,11 @@ export function rest_props(props, exclude, name) {
/** /**
* The proxy handler for legacy $$restProps and $$props * The proxy handler for legacy $$restProps and $$props
* @type {ProxyHandler<{ props: Record<string | symbol, unknown>, exclude: Array<string | symbol>, special: Record<string | symbol, (v?: unknown) => unknown>, version: Source<number>, parent_effect: Effect }>}} * @type {ProxyHandler<{ props: Record<string | symbol, unknown>, exclude: Set<string | symbol>, special: Record<string | symbol, (v?: unknown) => unknown>, version: Source<number>, parent_effect: Effect }>}}
*/ */
const legacy_rest_props_handler = { const legacy_rest_props_handler = {
get(target, key) { get(target, key) {
if (target.exclude.includes(key)) return; if (target.exclude.has(key)) return;
get(target.version); get(target.version);
return key in target.special ? target.special[key]() : target.props[key]; return key in target.special ? target.special[key]() : target.props[key];
}, },
@ -132,7 +132,7 @@ const legacy_rest_props_handler = {
return true; return true;
}, },
getOwnPropertyDescriptor(target, key) { getOwnPropertyDescriptor(target, key) {
if (target.exclude.includes(key)) return; if (target.exclude.has(key)) return;
if (key in target.props) { if (key in target.props) {
return { return {
enumerable: true, enumerable: true,
@ -143,23 +143,23 @@ const legacy_rest_props_handler = {
}, },
deleteProperty(target, key) { deleteProperty(target, key) {
// Svelte 4 allowed for deletions on $$restProps // Svelte 4 allowed for deletions on $$restProps
if (target.exclude.includes(key)) return true; if (target.exclude.has(key)) return true;
target.exclude.push(key); target.exclude.add(key);
update(target.version); update(target.version);
return true; return true;
}, },
has(target, key) { has(target, key) {
if (target.exclude.includes(key)) return false; if (target.exclude.has(key)) return false;
return key in target.props; return key in target.props;
}, },
ownKeys(target) { ownKeys(target) {
return Reflect.ownKeys(target.props).filter((key) => !target.exclude.includes(key)); return Reflect.ownKeys(target.props).filter((key) => !target.exclude.has(key));
} }
}; };
/** /**
* @param {Record<string, unknown>} props * @param {Record<string, unknown>} props
* @param {string[]} exclude * @param {Set<string>} exclude
* @returns {Record<string, unknown>} * @returns {Record<string, unknown>}
*/ */
export function legacy_rest_props(props, exclude) { export function legacy_rest_props(props, exclude) {

@ -350,7 +350,7 @@ export function slot(renderer, $$props, name, slot_props, fallback_fn) {
/** /**
* @param {Record<string, unknown>} props * @param {Record<string, unknown>} props
* @param {string[]} rest * @param {Set<string>} rest
* @returns {Record<string, unknown>} * @returns {Record<string, unknown>}
*/ */
export function rest_props(props, rest) { export function rest_props(props, rest) {
@ -358,7 +358,7 @@ export function rest_props(props, rest) {
const rest_props = {}; const rest_props = {};
let key; let key;
for (key of Object.keys(props)) { for (key of Object.keys(props)) {
if (!rest.includes(key)) { if (!rest.has(key)) {
rest_props[key] = props[key]; rest_props[key] = props[key];
} }
} }

@ -121,7 +121,7 @@ export function to_array(value, n) {
/** /**
* @param {Record<string | symbol, unknown>} obj * @param {Record<string | symbol, unknown>} obj
* @param {Array<string | symbol>} keys * @param {Set<string | symbol>} keys
* @returns {Record<string | symbol, unknown>} * @returns {Record<string | symbol, unknown>}
*/ */
export function exclude_from_object(obj, keys) { export function exclude_from_object(obj, keys) {
@ -129,13 +129,13 @@ export function exclude_from_object(obj, keys) {
var result = {}; var result = {};
for (var key in obj) { for (var key in obj) {
if (!keys.includes(key)) { if (!keys.has(key)) {
result[key] = obj[key]; result[key] = obj[key];
} }
} }
for (var symbol of Object.getOwnPropertySymbols(obj)) { for (var symbol of Object.getOwnPropertySymbols(obj)) {
if (Object.propertyIsEnumerable.call(obj, symbol) && !keys.includes(symbol)) { if (Object.propertyIsEnumerable.call(obj, symbol) && !keys.has(symbol)) {
result[symbol] = obj[symbol]; result[symbol] = obj[symbol];
} }
} }

Loading…
Cancel
Save