fix: use cached indexOf array prototype method internally (#14912)

pull/14918/head
Dominic Gannaway 5 days ago committed by GitHub
parent a8ca375c57
commit dbdb8cd7fd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: use cached indexOf array prototype method internally

@ -1,6 +1,6 @@
/** @import { ComponentContext, Derived, Effect, Reaction, Signal, Source, Value } from '#client' */ /** @import { ComponentContext, Derived, Effect, Reaction, Signal, Source, Value } from '#client' */
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { define_property, get_descriptors, get_prototype_of } from '../shared/utils.js'; import { define_property, get_descriptors, get_prototype_of, index_of } from '../shared/utils.js';
import { import {
destroy_block_effect_children, destroy_block_effect_children,
destroy_effect_children, destroy_effect_children,
@ -448,7 +448,7 @@ export function update_reaction(reaction) {
function remove_reaction(signal, dependency) { function remove_reaction(signal, dependency) {
let reactions = dependency.reactions; let reactions = dependency.reactions;
if (reactions !== null) { if (reactions !== null) {
var index = reactions.indexOf(signal); var index = index_of.call(reactions, signal);
if (index !== -1) { if (index !== -1) {
var new_length = reactions.length - 1; var new_length = reactions.length - 1;
if (new_length === 0) { if (new_length === 0) {

@ -1,6 +1,7 @@
// Store the references to globals in case someone tries to monkey patch these, causing the below // Store the references to globals in case someone tries to monkey patch these, causing the below
// to de-opt (this occurs often when using popular extensions). // to de-opt (this occurs often when using popular extensions).
export var is_array = Array.isArray; export var is_array = Array.isArray;
export var index_of = Array.prototype.indexOf;
export var array_from = Array.from; export var array_from = Array.from;
export var object_keys = Object.keys; export var object_keys = Object.keys;
export var define_property = Object.defineProperty; export var define_property = Object.defineProperty;

Loading…
Cancel
Save