From 854c2e52512a04ab9df99eea40b32ac31772c927 Mon Sep 17 00:00:00 2001 From: Eli Belash Date: Wed, 28 Aug 2019 21:45:25 +0300 Subject: [PATCH] Binding.Util: Minor perf-op --- src/TensorFlowNET.Core/Binding.Util.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/TensorFlowNET.Core/Binding.Util.cs b/src/TensorFlowNET.Core/Binding.Util.cs index bfbfa4ec..d723283f 100644 --- a/src/TensorFlowNET.Core/Binding.Util.cs +++ b/src/TensorFlowNET.Core/Binding.Util.cs @@ -178,13 +178,18 @@ namespace Tensorflow public static IEnumerable<(TKey, TValue)> enumerate(KeyValuePair[] values) { - foreach (var item in values) + var len = values.Length; + for (var i = 0; i < len; i++) + { + var item = values[i]; yield return (item.Key, item.Value); + } } public static IEnumerable<(int, T)> enumerate(IList values) { - for (int i = 0; i < values.Count; i++) + var len = values.Count; + for (int i = 0; i < len; i++) yield return (i, values[i]); }