Fix perf. regression caused by signed/unsigned comp (#79137)
authorAdeel Mujahid <3840695+am11@users.noreply.github.com>
Thu, 15 Dec 2022 10:17:53 +0000 (12:17 +0200)
committerGitHub <noreply@github.com>
Thu, 15 Dec 2022 10:17:53 +0000 (11:17 +0100)
src/libraries/System.Private.CoreLib/src/System/Collections/Generic/Queue.cs

index e9121fc..98a2f20 100644 (file)
@@ -453,7 +453,7 @@ namespace System.Collections.Generic
 
                 // Cache some fields in locals to decrease code size
                 T[] array = _q._array;
-                int capacity = array.Length;
+                uint capacity = (uint)array.Length;
 
                 // _index represents the 0-based index into the queue, however the queue
                 // doesn't have to start from 0 and it may not even be stored contiguously in memory.
@@ -467,7 +467,7 @@ namespace System.Collections.Generic
                     // Replacing it with simple comparison/subtraction operations sped up
                     // the average foreach loop by 2x.
 
-                    arrayIndex -= (uint)capacity; // wrap around if needed
+                    arrayIndex -= capacity; // wrap around if needed
                 }
 
                 _currentElement = array[arrayIndex];