diff --git a/src/CoreFoundation/CFArray.cs b/src/CoreFoundation/CFArray.cs index c597ec4e0fe8..15f4ec6a5a51 100644 --- a/src/CoreFoundation/CFArray.cs +++ b/src/CoreFoundation/CFArray.cs @@ -53,6 +53,9 @@ namespace CoreFoundation { // interesting bits: https://github.com/opensource-apple/CF/blob/master/CFArray.c public partial class CFArray : NativeObject { + // this cache the handle instead of issuing a native call + internal static NativeHandle CFNullHandle = _CFNullHandle; + #if !NET internal CFArray (NativeHandle handle) : base (handle, false) diff --git a/src/corefoundation.cs b/src/corefoundation.cs index c454a2ea6a60..1f1d063157b1 100644 --- a/src/corefoundation.cs +++ b/src/corefoundation.cs @@ -33,7 +33,7 @@ interface CFAllocator { interface CFArray { [Internal][Field ("kCFNull")] - IntPtr /* CFNullRef */ CFNullHandle { get; } + IntPtr /* CFNullRef */ _CFNullHandle { get; } } [Partial] diff --git a/tests/perftest/NativeArrayPerf.cs b/tests/perftest/NativeArrayPerf.cs index 1432a3f9e542..7ba8c67418b5 100644 --- a/tests/perftest/NativeArrayPerf.cs +++ b/tests/perftest/NativeArrayPerf.cs @@ -32,5 +32,17 @@ public void Create () var native = CFArray.Create (array); CFString.ReleaseNative (native); // that's a `CFObject.CFRelease` with a null-check } + + int error; + + [Benchmark] + public void ArrayFromHandleFunc () + { + var native = CFArray.Create (array); + var managed = CFArray.ArrayFromHandle (native); + if (managed.Length != array.Length) + error++; + CFString.ReleaseNative (native); // that's a `CFObject.CFRelease` with a null-check + } } }