Skip to content

Commit

Permalink
[corefoundation] Cache kCFNull to avoid native calls (#15146)
Browse files Browse the repository at this point in the history
  • Loading branch information
spouliot authored May 30, 2022
1 parent 7ad9f88 commit d869a68
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/CoreFoundation/CFArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/corefoundation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ interface CFAllocator {
interface CFArray {

[Internal][Field ("kCFNull")]
IntPtr /* CFNullRef */ CFNullHandle { get; }
IntPtr /* CFNullRef */ _CFNullHandle { get; }
}

[Partial]
Expand Down
12 changes: 12 additions & 0 deletions tests/perftest/NativeArrayPerf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSNumber> (native);
if (managed.Length != array.Length)
error++;
CFString.ReleaseNative (native); // that's a `CFObject.CFRelease` with a null-check
}
}
}

5 comments on commit d869a68

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

💻 [CI Build] Tests on macOS Mac Catalina (10.15) passed 💻

All tests on macOS Mac Catalina (10.15) passed.

Pipeline on Agent
Hash: d869a6868a0a1fb33a1bbec34a5b1542c227b9b8

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

📋 [CI Build] API Diff 📋

API diff (for current PR)

ℹ️ API Diff (from PR only) (please review changes)

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

API diff (vs stable)

✅ API Diff from stable

API diff: vsdrops gist

Xamarin
.NET
Xamarin vs .NET
iOS vs Mac Catalyst (.NET)

Generator diff

ℹ️ Generator Diff (please review changes)

Pipeline on Agent XAMMINI-047.Monterey'
Hash: d869a6868a0a1fb33a1bbec34a5b1542c227b9b8

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ [CI Build] Tests on macOS M1 - Mac Big Sur (11.5) failed ❌

Failed tests are:

  • xammac_tests
  • monotouch-test

Pipeline on Agent
Hash: d869a6868a0a1fb33a1bbec34a5b1542c227b9b8

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

📚 [CI Build] Artifacts 📚

Artifacts were not provided.

Pipeline on Agent XAMMINI-055.Monterey'
Hash: d869a6868a0a1fb33a1bbec34a5b1542c227b9b8

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ [CI Build] Tests failed on VSTS: simulator tests iOS ❌

Tests failed on VSTS: simulator tests iOS.

Test results

14 tests failed, 220 tests passed.

Failed tests

  • introspection/watchOS 32-bits - simulator/Debug: Crashed
  • link sdk/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemCoreTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemRuntimeSerializationTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemTransactionsTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemXmlTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono MonoRuntimeTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono SystemDataTests/watchOS 32-bits - simulator/Debug: Crashed
  • [NUnit] Mono CorlibTests/watchOS 32-bits - simulator/Debug: Crashed
  • [xUnit] Mono SystemLinqXunit/watchOS 32-bits - simulator/Debug: Crashed
  • [xUnit] Mono SystemNumericsXunit/watchOS 32-bits - simulator/Debug: Crashed
  • [xUnit] Mono SystemNetHttpUnitTestsXunit/watchOS 32-bits - simulator/Debug: Crashed
  • mscorlib Part 2/watchOS 32-bits - simulator/Debug: Crashed
  • [xUnit] Mono SystemCoreXunit Part 2/watchOS 32-bits - simulator/Debug: Crashed

Pipeline on Agent XAMBOT-1098.Monterey'
[corefoundation] Cache kCFNull to avoid native calls (#15146)

Please sign in to comment.