Skip to content

perf: Remove pointless memory allocation for gridSelectionHasItem #1081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ImmortalRabbit
Copy link
Contributor

Remove pointless allocation for gridSelectionHasItem according to FIXME

@lukasmasuch lukasmasuch requested a review from Copilot August 14, 2025 11:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the gridSelectionHasItem function by removing an unnecessary array allocation that was creating a temporary array to check selection ranges. Instead of creating an array to combine sel.current.range and sel.current.rangeStack, the code now checks the current range directly and then iterates through the range stack separately.

  • Eliminates pointless memory allocation by avoiding array creation and spread operation
  • Maintains the same functionality while improving performance
  • Addresses a FIXME comment indicating the optimization opportunity

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

const toCheck = [sel.current.range, ...sel.current.rangeStack]; // FIXME: pointless alloc
for (const r of toCheck) {
// dont we have a function for this?
if (col >= sel.current.range.x && col < sel.current.range.x + sel.current.range.width && row >= sel.current.range.y && row < sel.current.range.y + sel.current.range.height) return true;
Copy link
Preview

Copilot AI Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This line is quite long and complex with multiple property accesses. Consider extracting variables for sel.current.range and the boundary calculations to improve readability.

Suggested change
if (col >= sel.current.range.x && col < sel.current.range.x + sel.current.range.width && row >= sel.current.range.y && row < sel.current.range.y + sel.current.range.height) return true;
const range = sel.current.range;
const xMin = range.x;
const xMax = range.x + range.width;
const yMin = range.y;
const yMax = range.y + range.height;
if (col >= xMin && col < xMax && row >= yMin && row < yMax) return true;

Copilot uses AI. Check for mistakes.

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.

1 participant