Skip to content

Commit 5bd4716

Browse files
committed
Refactor circular buffer increment logic
Simplified increment operations for _head and _count in ConcurrentCircularBuffer. Combined increment and comparison for _head and used pre-increment for _count to improve code clarity.
1 parent 2c8c335 commit 5bd4716

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/Collections/ConcurrentCircularBuffer.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,22 @@ public void Add(T item)
2121
lock (_sync)
2222
{
2323
var tail = _head + _count;
24-
if (tail >= _capacity)
24+
if (tail >= _capacity)
2525
{
2626
tail -= _capacity;
2727
}
2828

2929
_buffer[tail] = item;
3030
if (_count == _capacity)
3131
{
32-
_head++;
33-
if (_head == _capacity)
32+
if (++_head == _capacity)
3433
{
3534
_head = 0;
3635
}
3736
}
3837
else
3938
{
40-
_count++;
39+
++_count;
4140
}
4241
}
4342
}
@@ -51,7 +50,7 @@ public void TakeSnapshot(List<T> target)
5150
for (var i = 0; i < _count; ++i)
5251
{
5352
var index = _head + i;
54-
if (index >= _capacity)
53+
if (index >= _capacity)
5554
{
5655
index -= _capacity;
5756
}

0 commit comments

Comments
 (0)