Skip to content

Conversation

@konard
Copy link
Member

@konard konard commented Sep 13, 2025

Summary

This PR fixes the bug in the ArrayPool<T>.Resize method where resizing to the same size would unnecessarily:

  • Allocate a new array from the pool
  • Copy data from source to destination
  • Dispose the original array

Changes Made

  • Fixed ArrayPool[T].cs:76-92: Added early return optimization when sourceArray.LongLength == size
  • Added ArrayPoolTests.cs: Comprehensive unit tests covering:
    • Same size resize (returns same object reference)
    • Different size resize (creates new object)
    • Resize to larger size (copies data, fills with defaults)
    • Empty array resize
    • Resize to zero size

Test Results

✅ All 25 tests pass (5 new + 20 existing)
✅ No regressions introduced
✅ Fix confirmed through reference equality checks

Performance Impact

When resizing to the same size:

  • Before: Always allocate + copy + dispose
  • After: Simple reference return (O(1) instead of O(n))

Fixes #96

🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #96
@konard konard self-assigned this Sep 13, 2025
- Added optimization to return the same object when resizing to identical size
- Prevents unnecessary memory allocation and data copying
- Added comprehensive unit tests to verify the fix and prevent regressions
- All existing tests continue to pass

Fixes #96

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@konard konard changed the title [WIP] bug in method Fix ArrayPool Resize method when old and new sizes are the same Sep 13, 2025
@konard konard marked this pull request as ready for review September 13, 2025 18:05
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.

bug in method

2 participants