Skip to content

Conversation

Connormiha
Copy link

This change replaces .slice() with a direct index-based loop to avoid unnecessary array allocations and improve performance.
It also adds a safety check to ensure both nodes exist in parent.body, preventing potential runtime errors when either node is not found.
Uses indexOf(..., fromIndex) to reduce lookup time for the second node.

Behavior remains unchanged for valid inputs, while the function now fails gracefully for invalid ones.

@Connormiha Connormiha force-pushed the optimize-can-reported-items branch from 308ec78 to 5ff9700 Compare August 20, 2025 08:09
@willhoney7
Copy link
Owner

Hey! Thanks for submitting this. Can you explain why this is a helpful change? Like obviously if the indexOf returned -1 then it could be wrong, but was this actually happening to you in practice?

@Connormiha
Copy link
Author

@willhoney7
The main change is that a new array is no longer created using slice, which in turn also reduces the workload for the garbage collector. I added the check for -1 to avoid a hypothetical situation where there’s an attempt to access a non-existent index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants