Skip to content

Commit 72bc8de

Browse files
authored
Config adjustments and optimizations
1 parent 1af5cb9 commit 72bc8de

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,26 @@ public ConcurrentCircularBuffer(int capacity)
1515
{
1616
_capacity = capacity > 0 ? capacity : 1;
1717
_buffer = new T[_capacity];
18-
_head = 0;
19-
_count = 0;
2018
}
2119

2220
public void Add(T item)
2321
{
2422
lock (_sync)
2523
{
26-
var tail = (_head + _count) % _capacity;
27-
_buffer[tail] = item;
24+
int tail = _head + _count;
25+
if (tail >= _capacity)
26+
{
27+
tail -= _capacity;
28+
}
2829

30+
_buffer[tail] = item;
2931
if (_count == _capacity)
3032
{
31-
_head = (_head + 1) % _capacity;
33+
_head++;
34+
if (_head == _capacity)
35+
{
36+
_head = 0;
37+
}
3238
}
3339
else
3440
{
@@ -42,13 +48,18 @@ public void TakeSnapshot(List<T> target)
4248
lock (_sync)
4349
{
4450
target.Clear();
45-
target.Capacity = _count;
4651

47-
for (var i = 0; i < _count; i++)
52+
for (int i = 0; i < _count; ++i)
4853
{
49-
target.Add(_buffer[(_head + i) % _capacity]);
54+
int index = _head + i;
55+
if (index >= _capacity)
56+
{
57+
index -= _capacity;
58+
}
59+
60+
target.Add(_buffer[index]);
5061
}
5162
}
5263
}
5364
}
54-
}
65+
}

Serilog.Sinks.RichTextBox.WinForms.Colored/Sinks/RichTextBoxForms/RichTextBoxSinkOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public int MaxLogLines
6060
private set => _maxLogLines = value switch
6161
{
6262
< 1 => 1,
63-
> 512 => 512,
63+
> 2048 => 2048,
6464
_ => value
6565
};
6666
}

0 commit comments

Comments
 (0)