Skip to content

Commit 21b7270

Browse files
committed
Cache EntitlementExtensions.AllKeys
1 parent 44b2fee commit 21b7270

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Xamarin.MacDev/EntitlementExtensions.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ public static class EntitlementKeys
3939
public const string Siri = "com.apple.developer.siri";
4040
public const string APS = "aps-environment";
4141

42-
public static IEnumerable<string> AllKeys {
43-
get {
44-
var entitlementKeys = typeof (EntitlementKeys).GetFields (BindingFlags.Public | BindingFlags.Static).
45-
Where (f => f.FieldType == typeof (string)).
46-
Select (field => (string) field.GetValue (null)).
47-
ToList ();
42+
static string[] allKeys;
4843

49-
return entitlementKeys;
44+
public static string[] AllKeys {
45+
get {
46+
if (allKeys == null) {
47+
allKeys = typeof (EntitlementKeys).GetFields (BindingFlags.Public | BindingFlags.Static).
48+
Where (f => f.FieldType == typeof (string)).
49+
Select (field => (string) field.GetValue (null)).
50+
ToArray ();
51+
}
52+
53+
return allKeys;
5054
}
5155
}
5256
}
@@ -158,13 +162,14 @@ public static void SetPassBookIdentifiers (this PDictionary dict, PArray value)
158162
dict[EntitlementKeys.PassBookIdentifiers] = value;
159163
}
160164

161-
public static IEnumerable<string> GetEntitlementKeys (this PDictionary dict)
165+
public static List<string> GetEntitlementKeys (this PDictionary dict)
162166
{
163167
var enabledEntitlements = new List<string> ();
168+
var keys = EntitlementKeys.AllKeys;
164169

165-
foreach (var key in EntitlementKeys.AllKeys) {
166-
if (dict.ContainsKey (key))
167-
enabledEntitlements.Add (key);
170+
for (int i = 0; i < keys.Length; i++) {
171+
if (dict.ContainsKey (keys[i]))
172+
enabledEntitlements.Add (keys[i]);
168173
}
169174

170175
return enabledEntitlements;

0 commit comments

Comments
 (0)