Skip to content

Commit 86f6adb

Browse files
committed
Added Compare methods with ReadOnlySpan argumetns
1 parent 45f057f commit 86f6adb

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Memory.Extensions/MemEx.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,52 @@ public static bool Compare(byte* arr, byte[] with, int len)
231231
return Compare(arr, ptr, len);
232232
}
233233

234+
235+
[MethImpl(AggressiveInlining)]
236+
public static bool Compare(ReadOnlySpan<byte> arr, byte[] with, int len)
237+
{
238+
fixed (void* withPtr = with)
239+
fixed (void* ptr = arr)
240+
return Compare(ptr, withPtr, len);
241+
}
242+
243+
[MethImpl(AggressiveInlining)]
244+
public static bool Compare(byte[] arr, ReadOnlySpan<byte> with)
245+
{
246+
fixed (void* withPtr = with)
247+
fixed (void* ptr = arr)
248+
return Compare(ptr, withPtr, with.Length);
249+
}
250+
251+
[MethImpl(AggressiveInlining)]
252+
public static bool Compare(ReadOnlySpan<byte> arr, ReadOnlySpan<byte> with)
253+
{
254+
fixed (void* withPtr = with)
255+
fixed (void* ptr = arr)
256+
return Compare(ptr, withPtr, with.Length);
257+
}
258+
259+
[MethImpl(AggressiveInlining)]
260+
public static bool Compare(void* ptr, ReadOnlySpan<byte> with)
261+
{
262+
fixed (void* withPtr = with)
263+
return Compare(ptr, withPtr, with.Length);
264+
}
265+
266+
[MethImpl(AggressiveInlining)]
267+
public static bool Compare(ReadOnlySpan<byte> arr, byte* with, int len)
268+
{
269+
fixed (void* ptr = arr)
270+
return Compare(ptr, with, len);
271+
}
272+
273+
[MethImpl(AggressiveInlining)]
274+
public static bool Compare(byte* arr, ReadOnlySpan<byte> with, int len)
275+
{
276+
fixed (void* ptr = with)
277+
return Compare(arr, ptr, len);
278+
}
279+
234280
[MethImpl(AggressiveInlining)]
235281
public static bool Contains<T>(T* arr, int length, T val) where T : unmanaged
236282
{

Memory.Extensions/Memory.Extensions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<PackageId>Yotic.Memory.Extensions</PackageId>
99
<Title>Memory.Extensions</Title>
10-
<Version>1.1.1</Version>
10+
<Version>1.1.3</Version>
1111
<Authors>Yotic</Authors>
1212
<Company></Company>
1313
<Description>Memory utils for convenient work with memory, arrays and pointers</Description>

0 commit comments

Comments
 (0)