Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions benchmark.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dotnet run --project .\test\Hashids.net.benchmark\Hashids.net.benchmark.csproj -c Release
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dotnet clean
dotnet test
dotnet build -c Release
4 changes: 1 addition & 3 deletions src/Hashids.net/Hashids.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System.Collections.Generic;
using System;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.Extensions.ObjectPool;
using System.Buffers;

namespace HashidsNet
Expand All @@ -29,7 +27,7 @@ public partial class Hashids : IHashids
private char[] _salt;
private readonly int _minHashLength;

private readonly ObjectPool<StringBuilder> _sbPool = new DefaultObjectPool<StringBuilder>(new StringBuilderPooledObjectPolicy());
private readonly StringBuilderPool _sbPool = new();

// Creates the Regex in the first usage, speed up first use of non-hex methods
private static readonly Lazy<Regex> hexValidator = new(() => new Regex("^[0-9a-fA-F]+$", RegexOptions.Compiled));
Expand Down
10 changes: 1 addition & 9 deletions src/Hashids.net/Hashids.net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.ObjectPool">
<Version>5.0.5</Version>
</PackageReference>
<PackageReference Include="System.Buffers">
<Version>4.5.1</Version>
</PackageReference>
<PackageReference Include="System.Memory">
<Version>4.5.4</Version>
</PackageReference>
<PackageReference Include="System.Buffers" Version="4.5.1" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/Hashids.net/StringBuilderPool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Collections.Concurrent;
using System.Text;

namespace HashidsNet
{
internal class StringBuilderPool
{
private readonly ConcurrentBag<StringBuilder> _builders = new();

public StringBuilder Get() => _builders.TryTake(out StringBuilder sb) ? sb : new();

public void Return(StringBuilder sb)
{
sb.Clear();
_builders.Add(sb);
}
}
}