[Foundation] Improve NSArray.FromIntPtrs slightly.#24501
Conversation
* Enable nullability. * Simplify code, with both reduced memory footprint, and faster execution speed. * Add tests. * Add xml docs.
There was a problem hiding this comment.
Pull request overview
This PR improves the NSArray.FromIntPtrs methods by enabling nullable reference types, optimizing performance through the use of fixed statements instead of manual memory marshaling, adding comprehensive tests, and providing XML documentation.
Changes:
- Optimized memory management by replacing
Marshal.AllocHGlobal/FreeHGlobalwithfixedstatements - Added XML documentation for both
FromIntPtrsoverloads - Added three comprehensive unit tests covering normal usage, null input, and empty arrays
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/monotouch-test/Foundation/NSArray1Test.cs | Added three unit tests for FromIntPtrs(NativeHandle[]): normal case, null argument validation, and empty array handling |
| src/Foundation/NSArray.cs | Refactored both FromIntPtrs methods to use fixed statements for better performance, added XML documentation, enabled nullable reference types, and improved null handling |
| /// <summary>Create an <see cref="NSArray" /> from the specified pointers.</summary> | ||
| /// <param name="vals">Array of pointers (to <see cref="NSObject" /> instances).</param> | ||
| /// <remarks>If the <paramref name="vals" /> array is null, an <see cref="ArgumentNullException" /> is thrown.</remarks> | ||
| public static NSArray FromIntPtrs (NativeHandle [] vals) |
There was a problem hiding this comment.
The modifier order was changed from static public to public static. According to the coding guidelines, diffs should be kept as small as possible and preserve existing code formatting. Since the original method used static public, it should remain that way.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #bf6ce57] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #bf6ce57] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #bf6ce57] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #bf6ce57] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #bf6ce57] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #bf6ce57] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #bf6ce57] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
💻 [CI Build #bf6ce57] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #bf6ce57] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 119 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Contributes towards #17285.