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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Set up .NET Core
uses: actions/setup-dotnet@v4
uses: actions/setup-dotnet@v5
with:
dotnet-version: '9.0.x'
global-json-file: global.json

- run: dotnet --info
- name: Build solution and run all tests
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.200",
"version": "10.0.100",
"allowPrerelease": true,
"rollForward": "latestFeature"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,39 @@ internal static class FusionCacheInternalUtils
{
internal static class GeneratorUtils
{
private static readonly char[] _chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV".ToCharArray();
private static long _lastId = DateTime.UtcNow.Ticks;
private static readonly ThreadLocal<char[]> _buffer = new(() => new char[13]);

private static string GenerateOperationId(long id)
{
// SEE: https://nimaara.com/2018/10/10/generating-ids-in-csharp.html

char[] buffer = _buffer.Value!;

buffer[0] = _chars[(int)(id >> 60) & 31];
buffer[1] = _chars[(int)(id >> 55) & 31];
buffer[2] = _chars[(int)(id >> 50) & 31];
buffer[3] = _chars[(int)(id >> 45) & 31];
buffer[4] = _chars[(int)(id >> 40) & 31];
buffer[5] = _chars[(int)(id >> 35) & 31];
buffer[6] = _chars[(int)(id >> 30) & 31];
buffer[7] = _chars[(int)(id >> 25) & 31];
buffer[8] = _chars[(int)(id >> 20) & 31];
buffer[9] = _chars[(int)(id >> 15) & 31];
buffer[10] = _chars[(int)(id >> 10) & 31];
buffer[11] = _chars[(int)(id >> 5) & 31];
buffer[12] = _chars[(int)id & 31];

return new string(buffer, 0, buffer.Length);
const string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUV";
const int length = 13;
#if NETSTANDARD2_0
Span<char> buffer = stackalloc char[length];
WriteTo(buffer, id);
return buffer.ToString();
#else
return string.Create(length, id, WriteTo);
#endif

[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void WriteTo(Span<char> buffer, long id)
{
// This order (from 12 to 0) eliminates bound checks for all the assignments except the first one.
buffer[12] = chars[(int)id & 31];
buffer[11] = chars[(int)(id >> 5) & 31];
buffer[10] = chars[(int)(id >> 10) & 31];
buffer[9] = chars[(int)(id >> 15) & 31];
buffer[8] = chars[(int)(id >> 20) & 31];
buffer[7] = chars[(int)(id >> 25) & 31];
buffer[6] = chars[(int)(id >> 30) & 31];
buffer[5] = chars[(int)(id >> 35) & 31];
buffer[4] = chars[(int)(id >> 40) & 31];
buffer[3] = chars[(int)(id >> 45) & 31];
buffer[2] = chars[(int)(id >> 50) & 31];
buffer[1] = chars[(int)(id >> 55) & 31];
buffer[0] = chars[(int)(id >> 60) & 31];
}
}

public static string GenerateOperationId()
Expand Down
Loading