浏览代码

[asp.net] Store new heap size when shrinking it. Thanks to Rodrigo Kumpera for noticing it!

This should fix the IndexOutOfRangeError which occur after heap exceeds 8192 elements and is then
shrunk below that value.
Marek Habersack 14 年之前
父节点
当前提交
2ec75014bd
共有 1 个文件被更改,包括 8 次插入12 次删除
  1. 8 12
      mcs/class/System.Web/System.Web.Caching/CacheItemPriorityQueue.cs

+ 8 - 12
mcs/class/System.Web/System.Web.Caching/CacheItemPriorityQueue.cs

@@ -62,8 +62,9 @@ namespace System.Web.Caching
 
 		void ResizeHeap (int newSize)
 		{
-			//CacheItem[] oldHeap = heap;
+			CacheItem[] oldHeap = heap;
 			Array.Resize <CacheItem> (ref heap, newSize);
+			heapSize = newSize;
 			
 			// TODO: The code helps the GC in case the array is pinned. In such instance clearing
 			// the old array will release references to the CacheItems stored in there. If the
@@ -71,13 +72,10 @@ namespace System.Web.Caching
 			// Currently we don't know if the array is pinned or not so it's safer to always clear it.
 			// However when we have more precise stack scanning the code should be
 			// revisited.
-			//
-			// FIXME: code disabled for now as it causes NREX to be thrown in Bubble{Up,Down}
-			//
-			// if (oldHeap != null) {
-			// 	((IList)oldHeap).Clear ();
-			// 	oldHeap = null;
-			// }
+			if (oldHeap != null) {
+				((IList)oldHeap).Clear ();
+				oldHeap = null;
+			}
 		}
 		
 		CacheItem[] GetHeapWithGrow ()
@@ -89,10 +87,8 @@ namespace System.Web.Caching
 				return heap;
 			}
 
-			if (heapCount >= heapSize) {
-				heapSize <<= 1;
-				ResizeHeap (heapSize);
-			}
+			if (heapCount >= heapSize)
+				ResizeHeap (heapSize <<= 1);
 
 			return heap;
 		}