From 197cb36b96d4c844de7f00239210565ece2a7204 Mon Sep 17 00:00:00 2001 From: Christoph Fink Date: Sat, 7 Sep 2019 11:17:48 +0200 Subject: [PATCH] Fix for #1217 --- .../Core/Query/InternalTrees/VarVec.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/EntityFramework/Core/Query/InternalTrees/VarVec.cs b/src/EntityFramework/Core/Query/InternalTrees/VarVec.cs index 07a9d2c97a..ef7fb96fab 100644 --- a/src/EntityFramework/Core/Query/InternalTrees/VarVec.cs +++ b/src/EntityFramework/Core/Query/InternalTrees/VarVec.cs @@ -843,11 +843,11 @@ private static int GetArraySize(int n, int div) private class ArrayPool { - private Dictionary> dictionary; + private ConcurrentDictionary> dictionary; private ArrayPool() { - dictionary = new Dictionary>(); + dictionary = new ConcurrentDictionary>(); } private static readonly ArrayPool instance = new ArrayPool(); @@ -872,17 +872,7 @@ public int[] GetArray(int length) private ConcurrentBag GetBag(int length) { - ConcurrentBag arrays; - if (!dictionary.ContainsKey(length)) - { - arrays = new ConcurrentBag(); - dictionary[length] = arrays; - } - else - { - arrays = dictionary[length]; - } - return arrays; + return dictionary.GetOrAdd(length, l => new ConcurrentBag()); } public void PutArray(int[] arr)