[CoreFoundation/Foundation] Optimize getting a handle for NSNull and a null CFAllocator.#24775
[CoreFoundation/Foundation] Optimize getting a handle for NSNull and a null CFAllocator.#24775rolfbjarne wants to merge 1 commit intomainfrom
Conversation
…a null CFAllocator.
There was a problem hiding this comment.
Pull request overview
This PR optimizes handle access for NSNull and CFAllocator.Null by avoiding object allocation overhead. Instead of accessing .Handle on singleton wrapper objects, the code now uses direct IntPtr access via cached properties and field bindings.
Changes:
- Introduced
NSNull.NullHandleinternal property that caches the handle using lazy initialization - Added
NSNull._NullHandlebinding to directly retrieve the handle from Objective-C - Updated all
CFAllocator.Null.Handleusages to useCFAllocator.null_ptrdirectly - Removed 4 test methods from handle safety known failures list that now pass
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/foundation.cs | Added _NullHandle binding for direct IntPtr access to NSNull singleton handle |
| src/Foundation/NSNull.cs | Implemented NullHandle internal property with lazy initialization to cache the handle |
| src/Foundation/NSArray.cs | Replaced 3 occurrences of NSNull.Null.Handle with optimized NSNull.NullHandle |
| src/Foundation/NSArray_1.cs | Replaced NSNull.Null.Handle with NSNull.NullHandle in array creation |
| src/ObjCRuntime/BindAs.cs | Updated conversion code to use NSNull.NullHandle instead of NSNull.Null.Handle |
| src/SceneKit/SCNSkinner.cs | Changed to use NSNull.NullHandle in SCNMatrix4 array conversion |
| src/CoreMedia/CMBlockBuffer.cs | Optimized to use CFAllocator.null_ptr directly instead of CFAllocator.Null.Handle |
| src/CoreFoundation/CFAllocator.cs | Added comment guiding developers to use null_ptr for handle-only access |
| tests/cecil-tests/HandleSafety.KnownFailures.cs | Removed 4 methods that now pass handle safety tests due to optimizations |
✅ [CI Build #ac5fb29] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #ac5fb29] 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 |
✅ [CI Build #ac5fb29] Build passed (Build macOS tests) ✅Pipeline on Agent |
🔥 [CI Build #ac5fb29] Test results 🔥Test results❌ Tests failed on VSTS: test results 0 tests crashed, 5 tests failed, 151 tests passed. Failures❌ introspection tests2 tests failed, 4 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (MacCatalyst)1 tests failed, 14 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (macOS)1 tests failed, 11 tests passed.Failed tests
Html Report (VSDrops) Download ❌ monotouch tests (tvOS)1 tests failed, 10 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
No description provided.