Skip to content

Commit 08727d9

Browse files
committed
Merge span extension functions in a single class and move S(RO)Span<T> to Utils.
1 parent 1137124 commit 08727d9

4 files changed

Lines changed: 33 additions & 41 deletions

File tree

TACTSharp/Extensions/BinarySearchExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Runtime.CompilerServices;
33
using System.Runtime.InteropServices;
44

5+
using TACTSharp.Utils;
6+
57
namespace TACTSharp.Extensions
68
{
79
internal static class BinarySearchExtensions

TACTSharp/Extensions/SpanExtensions.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Runtime.CompilerServices;
22

3+
using TACTSharp.Utils;
4+
35
namespace TACTSharp.Extensions
46
{
57
internal static class SpanExtensions
@@ -11,5 +13,33 @@ public static StridedReadOnlySpan<T> WithStride<T>(this ReadOnlySpan<T> span, in
1113
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1214
public static StridedSpan<T> WithStride<T>(this Span<T> span, int stride)
1315
=> new(span, stride);
16+
17+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
18+
public static ushort ReadUInt16BE(this ReadOnlySpan<byte> source)
19+
=> BinaryPrimitives.ReadUInt16BigEndian(source);
20+
21+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
22+
public static short ReadInt16BE(this ReadOnlySpan<byte> source)
23+
=> BinaryPrimitives.ReadInt16BigEndian(source);
24+
25+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
26+
public static int ReadInt24BE(this ReadOnlySpan<byte> source)
27+
=> source[2] | source[1] << 8 | source[0] << 16;
28+
29+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
30+
public static int ReadInt32BE(this ReadOnlySpan<byte> source)
31+
=> BinaryPrimitives.ReadInt32BigEndian(source);
32+
33+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
34+
public static uint ReadUInt32BE(this ReadOnlySpan<byte> source)
35+
=> BinaryPrimitives.ReadUInt32BigEndian(source);
36+
37+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
38+
public static long ReadInt40BE(this ReadOnlySpan<byte> source)
39+
=> source[4] | source[3] << 8 | source[2] << 16 | source[1] << 24 | source[0] << 32;
40+
41+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
42+
public static string ReadNullTermString(this ReadOnlySpan<byte> source)
43+
=> Encoding.UTF8.GetString(source[..source.IndexOf((byte)0)]);
1444
}
1545
}

TACTSharp/Utils/Extensions.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Runtime.CompilerServices;
22

3-
namespace TACTSharp
3+
namespace TACTSharp.Utils
44
{
55
internal readonly ref struct StridedSpan<T>(Span<T> data, int stride)
66
{

0 commit comments

Comments
 (0)