Skip to content

Commit 36fd1ed

Browse files
committed
Refactor StringBuilderPool.ToPool method
Removed manual control of StringBuilder instance population in the pool and replaced it with a dedicated method, ReturnToPool, for clarity and simplicity. This change supports better code maintainability and less complexity when interacting with the StringBuilder pool.
1 parent db77c16 commit 36fd1ed

File tree

1 file changed

+1
-19
lines changed

1 file changed

+1
-19
lines changed

src/AngleSharp/Text/StringBuilderPool.cs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,7 @@ public static StringBuilder Obtain()
5858
public static String ToPool(this StringBuilder sb)
5959
{
6060
var result = sb.ToString();
61-
62-
lock (_lock)
63-
{
64-
var current = _builder.Count;
65-
66-
if (sb.Capacity > _limit)
67-
{
68-
// Drop large instances
69-
}
70-
else if (current == _count)
71-
{
72-
DropMinimum(sb);
73-
}
74-
else if (current < Math.Min(2, _count) || _builder.Peek().Capacity < sb.Capacity)
75-
{
76-
_builder.Push(sb);
77-
}
78-
}
79-
61+
ReturnToPool(sb);
8062
return result;
8163
}
8264

0 commit comments

Comments
 (0)