Skip to content

Commit dbdb8cd

Browse files
authored
fix: use cached indexOf array prototype method internally (#14912)
1 parent a8ca375 commit dbdb8cd

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

.changeset/real-dolphins-return.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: use cached indexOf array prototype method internally

packages/svelte/src/internal/client/runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @import { ComponentContext, Derived, Effect, Reaction, Signal, Source, Value } from '#client' */
22
import { DEV } from 'esm-env';
3-
import { define_property, get_descriptors, get_prototype_of } from '../shared/utils.js';
3+
import { define_property, get_descriptors, get_prototype_of, index_of } from '../shared/utils.js';
44
import {
55
destroy_block_effect_children,
66
destroy_effect_children,
@@ -448,7 +448,7 @@ export function update_reaction(reaction) {
448448
function remove_reaction(signal, dependency) {
449449
let reactions = dependency.reactions;
450450
if (reactions !== null) {
451-
var index = reactions.indexOf(signal);
451+
var index = index_of.call(reactions, signal);
452452
if (index !== -1) {
453453
var new_length = reactions.length - 1;
454454
if (new_length === 0) {

packages/svelte/src/internal/shared/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Store the references to globals in case someone tries to monkey patch these, causing the below
22
// to de-opt (this occurs often when using popular extensions).
33
export var is_array = Array.isArray;
4+
export var index_of = Array.prototype.indexOf;
45
export var array_from = Array.from;
56
export var object_keys = Object.keys;
67
export var define_property = Object.defineProperty;

0 commit comments

Comments
 (0)