Skip to content

Commit 854c2e5

Browse files
committed
Binding.Util: Minor perf-op
1 parent 6b2fa40 commit 854c2e5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/TensorFlowNET.Core/Binding.Util.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,18 @@ public static float time()
178178

179179
public static IEnumerable<(TKey, TValue)> enumerate<TKey, TValue>(KeyValuePair<TKey, TValue>[] values)
180180
{
181-
foreach (var item in values)
181+
var len = values.Length;
182+
for (var i = 0; i < len; i++)
183+
{
184+
var item = values[i];
182185
yield return (item.Key, item.Value);
186+
}
183187
}
184188

185189
public static IEnumerable<(int, T)> enumerate<T>(IList<T> values)
186190
{
187-
for (int i = 0; i < values.Count; i++)
191+
var len = values.Count;
192+
for (int i = 0; i < len; i++)
188193
yield return (i, values[i]);
189194
}
190195

0 commit comments

Comments
 (0)