Skip to content

Commit 4b12b43

Browse files
committed
refactor: Use int list as there is no other use
1 parent 4681c5d commit 4b12b43

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/LinkDotNet.StringBuilder/TypedSpanList.cs renamed to src/LinkDotNet.StringBuilder/IntegerSpanList.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,28 @@ namespace LinkDotNet.StringBuilder;
66
/// <summary>
77
/// Represents a List based on the <see cref="Span{T}"/> type.
88
/// </summary>
9-
/// <typeparam name="T">Any struct.</typeparam>
109
[StructLayout(LayoutKind.Auto)]
1110
[SkipLocalsInit]
12-
internal ref struct TypedSpanList<T>
13-
where T : struct
11+
internal ref struct IntegerSpanList
1412
{
15-
private Span<T> buffer;
13+
private Span<int> buffer;
1614
private int count;
1715

1816
/// <summary>
19-
/// Initializes a new instance of the <see cref="TypedSpanList{T}"/> struct.
17+
/// Initializes a new instance of the <see cref="IntegerSpanList"/> struct.
2018
/// </summary>
2119
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22-
public TypedSpanList()
20+
public IntegerSpanList()
2321
{
24-
buffer = GC.AllocateUninitializedArray<T>(8);
22+
buffer = GC.AllocateUninitializedArray<int>(8);
2523
count = 0;
2624
}
2725

2826
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29-
public readonly ReadOnlySpan<T> AsSpan() => buffer[..count];
27+
public readonly ReadOnlySpan<int> AsSpan() => buffer[..count];
3028

3129
[MethodImpl(MethodImplOptions.AggressiveInlining)]
32-
public void Add(T value)
30+
public void Add(int value)
3331
{
3432
if (count >= buffer.Length)
3533
{
@@ -45,7 +43,7 @@ private void Grow(int capacity = 0)
4543
{
4644
var currentSize = buffer.Length;
4745
var newSize = capacity > 0 ? capacity : currentSize * 2;
48-
var rented = GC.AllocateUninitializedArray<T>(newSize);
46+
var rented = GC.AllocateUninitializedArray<int>(newSize);
4947
buffer[..count].CopyTo(rented);
5048
buffer = rented;
5149
}

src/LinkDotNet.StringBuilder/NaiveSearch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static ReadOnlySpan<int> FindAll(ReadOnlySpan<char> text, ReadOnlySpan<ch
2020
return ReadOnlySpan<int>.Empty;
2121
}
2222

23-
var hits = new TypedSpanList<int>();
23+
var hits = new IntegerSpanList();
2424

2525
for (var i = 0; i < text.Length - word.Length + 1; i++)
2626
{

0 commit comments

Comments
 (0)