Ensure that the buffer is cleared when disposed#12
Merged
Conversation
Add an overload to ReturnRentedBuffer() which allows you to clear the buffer.
There was a problem hiding this comment.
Pull Request Overview
This PR adds an overload to ReturnRentedBuffer that accepts a clearBuffer flag and updates calls (including in Dispose) to optionally clear the buffer when returning it to the pool.
- Introduce
ReturnRentedBuffer(char[]? buffer, bool clearBuffer) - Update existing no-arg overload to call new overload with
clearBuffer = false - Change
Disposeto return buffer withclearBuffer = true
Comments suppressed due to low confidence (2)
Solutions/Corvus.HighPerformance/Corvus.HighPerformance/ValueStringBuilder.cs:92
- The XML doc for the
clearBufferparameter is missing a closing tag and uses<para>instead of<param>. Change to<param name="clearBuffer">If true, the buffer will be cleared before returning.</param>.
/// <para name="clearBuffer">If <see langword="true"/> then clear the buffer when returned.
Solutions/Corvus.HighPerformance/Corvus.HighPerformance/ValueStringBuilder.cs:93
- [nitpick] Consider adding unit tests for the new overload to verify that
clearBuffercorrectly clears data when the flag is true, and leaves it intact when false.
public static void ReturnRentedBuffer(char[]? buffer, bool clearBuffer)
Code Coverage Summary Report - Linux (net8.0)Summary
CoverageCorvus.HighPerformance - 65.7%
Corvus.HighPerformance.Specs - 94.7%
|
Code Coverage Summary Report - Windows (net8.0)Summary
CoverageCorvus.HighPerformance - 65.7%
Corvus.HighPerformance.Specs - 94.7%
|
Code Coverage Summary Report - Windows (net481)Summary
CoverageCorvus.HighPerformance - 66.5%
Corvus.HighPerformance.Specs - 94.3%
|
idg10
approved these changes
Jul 7, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add an overload to ReturnRentedBuffer() which allows you to clear the buffer.