RecyclableList.IndexOf performance improvements.

This commit is contained in:
mlemanczyk committed 2023-05-21 15:42:32 +02:00
1 parent 209dac1808
commit b458f450fc
10 files changed
+502 -309

No files matched your search

@@ -2,7 +2,7 @@ namespace Recyclable.Collections.Parallel
{
public sealed class ParallelSynchronizationContext : IDisposable
{
public readonly ManualResetEventSlimmer ItemFoundSignal;
internal bool _isItemFound;
public readonly Barrier AllDoneSignal;
public long FoundItemIndex;
@@ -11,16 +11,21 @@ namespace Recyclable.Collections.Parallel
public ParallelSynchronizationContext()
{
ItemFoundSignal = ManualResetEventSlimmerPool.Create(false);
AllDoneSignal = new(0);
AllDoneSignal = new(0);
}
public ParallelSynchronizationContext(int participantCount)
{
ItemFoundSignal = ManualResetEventSlimmerPool.Create(false);
AllDoneSignal = new(participantCount);
}
public void SetItemFound()
{
_isItemFound = true;
}
public bool IsItemFound => _isItemFound;
public void Dispose()
{
if (!_returned)
@@ -30,7 +35,6 @@ namespace Recyclable.Collections.Parallel
}
else
{
ItemFoundSignal.Dispose();
AllDoneSignal.Dispose();
GC.SuppressFinalize(this);
}
@@ -17,9 +17,9 @@ namespace Recyclable.Collections.Parallel
_updateLock.Exit(false);
}
if (context.ItemFoundSignal._isSet)
if (context._isItemFound)
{
context.ItemFoundSignal.Reset();
context._isItemFound = false;
}
switch (context.AllDoneSignal.ParticipantsRemaining)
@@ -40,7 +40,7 @@ namespace Recyclable.Collections.Parallel
if (context.FoundItemIndex >= 0)
{
context.FoundItemIndex = -1L;
context.FoundItemIndex = RecyclableDefaults.ItemNotFoundIndexLong;
}
context._returned = false;