From 9676ee74859cebcde7885cffb9d4554ac1a380c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Lema=C5=84czyk?= Date: Fri, 3 Mar 2023 01:33:41 +0100 Subject: [PATCH] Performance improvement for low no. of items --- Recyclable.Collections/RecyclableList.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 2007beb..da48779 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -516,6 +516,11 @@ namespace Recyclable.Collections return false; } + if (_lastBlockIndex == 0 || (_lastBlockIndex == 1 && _nextItemIndex == 0)) + { + return Array.IndexOf(_memoryBlocks[0], item, 0, (int)_longCount) >= 0; + } + Span memoryBlocksSpan = new(_memoryBlocks); int lastBlockIndex = _lastBlockIndex; for (int blockIndex = 0; blockIndex < lastBlockIndex; blockIndex++)