fix: avoid using dev-mode array.includes wrapper on internal array checks (#17536)

* fix: avoid using dev-mode array.includes wrapper on internal array checks

* use includes rather than index_of

* unused imports

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/17541/head
David 3 months ago committed by GitHub
parent c041d122ba
commit bec90d4801
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: avoid using dev-mode array.includes wrapper on internal array checks

@ -21,7 +21,7 @@ import {
MANAGED_EFFECT
} from '#client/constants';
import { async_mode_flag } from '../../flags/index.js';
import { deferred, define_property } from '../../shared/utils.js';
import { deferred, define_property, includes } from '../../shared/utils.js';
import {
active_effect,
get,
@ -775,7 +775,7 @@ function depends_on(reaction, sources, checked) {
if (reaction.deps !== null) {
for (const dep of reaction.deps) {
if (sources.includes(dep)) {
if (includes.call(sources, dep)) {
return true;
}

@ -33,7 +33,7 @@ import { component_context } from '../context.js';
import { UNINITIALIZED } from '../../../constants.js';
import { batch_values, current_batch } from './batch.js';
import { unset_context } from './async.js';
import { deferred } from '../../shared/utils.js';
import { deferred, includes } from '../../shared/utils.js';
import { set_signal_status, update_derived_status } from './status.js';
/** @type {Effect | null} */
@ -322,7 +322,7 @@ export function execute_derived(derived) {
let prev_eager_effects = eager_effects;
set_eager_effects(new Set());
try {
if (stack.includes(derived)) {
if (includes.call(stack, derived)) {
e.derived_references_self();
}

@ -31,6 +31,7 @@ import {
} from '#client/constants';
import * as e from '../errors.js';
import { legacy_mode_flag, tracing_mode_flag } from '../../flags/index.js';
import { includes } from '../../shared/utils.js';
import { tag_proxy } from '../dev/tracing.js';
import { get_error } from '../../shared/dev.js';
import { component_context, is_runes } from '../context.js';
@ -150,7 +151,7 @@ export function set(source, value, should_proxy = false) {
(!untracking || (active_reaction.f & EAGER_EFFECT) !== 0) &&
is_runes() &&
(active_reaction.f & (DERIVED | BLOCK_EFFECT | ASYNC | EAGER_EFFECT)) !== 0 &&
!current_sources?.includes(source)
(current_sources === null || !includes.call(current_sources, source))
) {
e.state_unsafe_mutation();
}

@ -1,6 +1,6 @@
/** @import { Derived, Effect, Reaction, Source, Value } from '#client' */
import { DEV } from 'esm-env';
import { get_descriptors, get_prototype_of, index_of } from '../shared/utils.js';
import { get_descriptors, get_prototype_of, includes, index_of } from '../shared/utils.js';
import {
destroy_block_effect_children,
destroy_effect_children,
@ -192,7 +192,7 @@ function schedule_possible_effect_self_invalidation(signal, effect, root = true)
var reactions = signal.reactions;
if (reactions === null) return;
if (!async_mode_flag && current_sources?.includes(signal)) {
if (!async_mode_flag && current_sources !== null && includes.call(current_sources, signal)) {
return;
}
@ -371,7 +371,7 @@ function remove_reaction(signal, dependency) {
// Destroying a child effect while updating a parent effect can cause a dependency to appear
// to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`
// allows us to skip the expensive work of disconnecting and immediately reconnecting it
(new_deps === null || !new_deps.includes(dependency))
(new_deps === null || !includes.call(new_deps, dependency))
) {
var derived = /** @type {Derived} */ (dependency);
@ -514,7 +514,7 @@ export function get(signal) {
// we don't add the dependency, because that would create a memory leak
var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;
if (!destroyed && !current_sources?.includes(signal)) {
if (!destroyed && (current_sources === null || !includes.call(current_sources, signal))) {
var deps = active_reaction.deps;
if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {
@ -542,7 +542,7 @@ export function get(signal) {
if (reactions === null) {
signal.reactions = [active_reaction];
} else if (!reactions.includes(active_reaction)) {
} else if (!includes.call(reactions, active_reaction)) {
reactions.push(active_reaction);
}
}

@ -2,6 +2,7 @@
// to de-opt (this occurs often when using popular extensions).
export var is_array = Array.isArray;
export var index_of = Array.prototype.indexOf;
export var includes = Array.prototype.includes;
export var array_from = Array.from;
export var object_keys = Object.keys;
export var define_property = Object.defineProperty;

Loading…
Cancel
Save