Skip to content

Refactor: Replace ArrayPool<T>.RentOwner extension with SpanPool<T>.Rent#74

Merged
Tyrrrz merged 3 commits intoprimefrom
copilot/refactor-arraypool-rentowner-to-spanpool-rent
Apr 19, 2026
Merged

Refactor: Replace ArrayPool<T>.RentOwner extension with SpanPool<T>.Rent#74
Tyrrrz merged 3 commits intoprimefrom
copilot/refactor-arraypool-rentowner-to-spanpool-rent

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 19, 2026

ISpanOwner<T> and its renting logic were awkwardly bolted onto ArrayPool<T> via an extension method. This promotes them to a first-class SpanPool<T> type with a cleaner, purpose-built API.

Changes

  • New PowerKit/SpanPool.cs — introduces SpanPool<T> with a Shared static property (backed by ArrayPool<T>.Shared) and a Rent(int minimumLength = 1) method returning ISpanOwner<T>; ISpanOwner<T> and the private ArrayPoolSpanOwner<T> impl move here from the old extensions file
  • Removed ArrayPoolExtensions.csextension(ArrayPool<T>) block with RentOwner is gone
  • Updated FileExtensions.cs — single call site updated accordingly
  • TestsArrayPoolExtensionsTests.cs replaced by SpanPoolTests.cs at the root test level
// Before
using var buffer = ArrayPool<byte>.Shared.RentOwner(bytes.Length * 2);

// After
using var buffer = SpanPool<byte>.Shared.Rent(bytes.Length * 2);

@Tyrrrz Tyrrrz added the enhancement New feature or request label Apr 19, 2026
@Tyrrrz Tyrrrz marked this pull request as ready for review April 19, 2026 11:13
Copilot AI review requested due to automatic review settings April 19, 2026 11:13
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Retain the coding style from the removed test file @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 00435dd. Each test now has a var pool = SpanPool<byte>.Shared; in its // Arrange section, matching the original style.

Comment thread PowerKit/Extensions/FileExtensions.cs Outdated
Comment thread PowerKit/SpanPool.cs Outdated
Copy link
Copy Markdown
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 refactors the temporary-span renting API by replacing the ArrayPool<T>.RentOwner() extension with a dedicated SpanPool<T> type, making the pooling abstraction a first-class concept in PowerKit.

Changes:

  • Added SpanPool<T> (backed by ArrayPool<T>) and moved ISpanOwner<T> + implementation into the new file.
  • Removed the ArrayPool<T>.RentOwner() extension and updated the only in-repo call site.
  • Replaced the old extension-focused tests with SpanPool-focused tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Show a summary per file
File Description
PowerKit/SpanPool.cs Introduces SpanPool<T> + ISpanOwner<T> and the pooled-span owner implementation.
PowerKit/Extensions/FileExtensions.cs Updates buffer renting in File.Contains() to use SpanPool<T>.Shared.Rent(...).
PowerKit/Extensions/ArrayPoolExtensions.cs Removes the old RentOwner extension implementation.
PowerKit.Tests/SpanPoolTests.cs Adds tests for renting and disposal behavior via SpanPool<T>.
PowerKit.Tests/Extensions/ArrayPoolExtensionsTests.cs Removes tests for the deleted RentOwner extension.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 19, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • example.com
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/PowerKit/PowerKit/PowerKit.Tests/bin/Release/net10.0/PowerKit.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/PowerKit/PowerKit/PowerKit.Tests/bin/Release/net10.0/PowerKit.Tests.deps.json /home/REDACTED/work/PowerKit/PowerKit/PowerKit.Tests/bin/Release/net10.0/testhost.dll --port 44713 --endpoint 127.0.0.1:044713 --role client --parentprocessid 4080 --datacollectionport 0 --telemetryoptedin false (dns block)
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/PowerKit/PowerKit/PowerKit.Tests/bin/Release/net10.0/PowerKit.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/PowerKit/PowerKit/PowerKit.Tests/bin/Release/net10.0/PowerKit.Tests.deps.json /home/REDACTED/work/PowerKit/PowerKit/PowerKit.Tests/bin/Release/net10.0/testhost.dll --port 41717 --endpoint 127.0.0.1:041717 --role client --parentprocessid 4390 --datacollectionport 0 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.88%. Comparing base (d826090) to head (e128826).
⚠️ Report is 2 commits behind head on prime.

Files with missing lines Patch % Lines
PowerKit/SpanPool.cs 80.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            prime      #74   +/-   ##
=======================================
  Coverage   93.88%   93.88%           
=======================================
  Files         128      128           
  Lines        2534     2536    +2     
  Branches      201      201           
=======================================
+ Hits         2379     2381    +2     
  Misses        112      112           
  Partials       43       43           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants