Skip to content

Commit

Permalink
fix: use cached indexOf array prototype method internally
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Jan 6, 2025
1 parent c4e9faa commit 6badd76
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-dolphins-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: use cached indexOf array prototype method internally
4 changes: 2 additions & 2 deletions packages/svelte/src/internal/client/runtime.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @import { ComponentContext, Derived, Effect, Reaction, Signal, Source, Value } from '#client' */
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 {
destroy_block_effect_children,
destroy_effect_children,
Expand Down Expand Up @@ -448,7 +448,7 @@ export function update_reaction(reaction) {
function remove_reaction(signal, dependency) {
let reactions = dependency.reactions;
if (reactions !== null) {
var index = reactions.indexOf(signal);
var index = index_of.call(reactions, signal);
if (index !== -1) {
var new_length = reactions.length - 1;
if (new_length === 0) {
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/src/internal/shared/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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).
export var is_array = Array.isArray;
export var index_of = Array.prototype.indexOf;
export var array_from = Array.from;
export var object_keys = Object.keys;
export var define_property = Object.defineProperty;
Expand Down

0 comments on commit 6badd76

Please sign in to comment.