Skip to content

Do not allocate new buffer if the current buffer is sufficient#9775

Merged
ReubenBond merged 1 commit intodotnet:mainfrom
willseward:fix-ensure-contig
Nov 18, 2025
Merged

Do not allocate new buffer if the current buffer is sufficient#9775
ReubenBond merged 1 commit intodotnet:mainfrom
willseward:fix-ensure-contig

Conversation

@willseward
Copy link
Contributor

@willseward willseward commented Nov 14, 2025

Current behavior is that if the currentSpan.Length == buffPos + length, then it will allocate a new buffer. It's not really a problem, but it over-allocates a buffer, when the current one is adequate.

Microsoft Reviewers: Open in CodeFlow

Copilot AI review requested due to automatic review settings November 14, 2025 15:43
Copy link
Contributor

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 fixes an off-by-one error in the EnsureContiguous method that caused unnecessary buffer allocation when the current buffer had exactly the required space available.

Key Changes:

  • Changed the boundary check in EnsureContiguous from < to <= to correctly handle the case where _bufferPos + length == _currentSpan.Length

@ReubenBond ReubenBond enabled auto-merge November 17, 2025 23:46
@ReubenBond ReubenBond added this pull request to the merge queue Nov 18, 2025
Merged via the queue into dotnet:main with commit 3313f81 Nov 18, 2025
29 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants