-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
203 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/core/StackExchange.Redis.Extensions.Core/Extensions/SpanExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using StackExchange.Redis.Extensions.Core.Models; | ||
|
||
namespace StackExchange.Redis.Extensions.Core.Extensions; | ||
|
||
internal static class SpanExtensions | ||
{ | ||
public static void EnumerateLines(this ReadOnlySpan<char> span, ref List<InfoDetail> data, ref string category) | ||
{ | ||
var start = 0; | ||
|
||
while (start < span.Length) | ||
{ | ||
var end = span[start..].IndexOf('\n'); | ||
ReadOnlySpan<char> line; | ||
|
||
if (end == -1) | ||
{ | ||
line = span[start..].Trim(); | ||
start = span.Length; // Termina il loop | ||
} | ||
else | ||
{ | ||
line = span[start..(start + end)].Trim(); | ||
start += end + 1; | ||
} | ||
|
||
// Gestisci ogni riga | ||
if (line.IsEmpty) | ||
continue; | ||
|
||
if (line[0] == '#') | ||
{ | ||
category = line[1..].Trim().ToString(); | ||
continue; | ||
} | ||
|
||
var idx = line.IndexOf(':'); | ||
if (idx > 0) | ||
{ | ||
var key = line[..idx].Trim(); | ||
var infoValue = line[(idx + 1)..].Trim(); | ||
|
||
data.Add(new InfoDetail(category, key.ToString(), infoValue.ToString())); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/core/StackExchange.Redis.Extensions.Core/Helpers/RedisKeyHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace StackExchange.Redis.Extensions.Core.Helpers; | ||
|
||
internal static class GenericsExtensions | ||
{ | ||
public static void FastIteration<TSource>(this ICollection<TSource>? request, Action<TSource, int> action) | ||
{ | ||
if (request == null) | ||
return; | ||
|
||
if (request is TSource[] sourceArray) | ||
{ | ||
ref var searchSpace = ref MemoryMarshal.GetReference(sourceArray.AsSpan()); | ||
|
||
for (var i = 0; i < sourceArray.Length; i++) | ||
{ | ||
ref var r = ref Unsafe.Add(ref searchSpace, i); | ||
|
||
action.Invoke(r, i); | ||
} | ||
} | ||
else | ||
{ | ||
var i = 0; | ||
foreach (var r in request) | ||
action.Invoke(r, i++); | ||
} | ||
} | ||
|
||
public static TResult[] ToFastArray<TSource, TResult>(this ICollection<TSource>? request, Func<TSource, TResult> action) | ||
{ | ||
if (request == null) | ||
return []; | ||
|
||
var result = new TResult[request.Count]; | ||
|
||
if (request is TSource[] sourceArray) | ||
{ | ||
ref var searchSpace = ref MemoryMarshal.GetReference(sourceArray.AsSpan()); | ||
|
||
for (var i = 0; i < sourceArray.Length; i++) | ||
{ | ||
ref var r = ref Unsafe.Add(ref searchSpace, i); | ||
|
||
result[i] = action.Invoke(r); | ||
} | ||
} | ||
/* | ||
This could be helpful when we drop old frameworks | ||
else if (request is List<TSource> sourceList) | ||
{ | ||
var span = CollectionsMarshal.AsSpan(sourceList); | ||
ref var searchSpace = ref MemoryMarshal.GetReference(span); | ||
for (var i = 0; i < span.Length; i++) | ||
{ | ||
ref var r = ref Unsafe.Add(ref searchSpace, i); | ||
result[i] = action.Invoke(r); | ||
} | ||
} | ||
*/ | ||
else | ||
{ | ||
var i = 0; | ||
foreach (var r in request) | ||
result[i++] = action.Invoke(r); | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.