fix(core): Updates slice with range selectors (#583)
- [X] Replaces Span slicing with range selection - [X] Replaces string slicing with range selection
This commit is contained in:
parent
9f9d990f85
commit
a0893b68c0
62 changed files with 363 additions and 382 deletions
|
|
@ -64,14 +64,14 @@ namespace Server.Tests.Network
|
|||
var strLength = fixedLength > -1 ? Math.Min(value.Length, fixedLength) : value.Length;
|
||||
var chars = value.AsSpan(0, strLength);
|
||||
|
||||
encoding.GetBytes(chars, buffer.Slice(offset));
|
||||
encoding.GetBytes(chars, buffer[offset..]);
|
||||
|
||||
var reader = new CircularBufferReader(buffer.SliceToLength(firstSize), buffer.Slice(firstSize));
|
||||
var reader = new CircularBufferReader(buffer[..firstSize], buffer[firstSize..]);
|
||||
reader.Seek(offset, SeekOrigin.Begin);
|
||||
|
||||
var actual = reader.ReadString(encoding, isSafe, fixedLength);
|
||||
|
||||
Assert.Equal(value.Substring(0, strLength), actual);
|
||||
Assert.Equal(value[..strLength], actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -82,7 +82,7 @@ namespace Server.Tests.Network
|
|||
expected[1] = 0x1;
|
||||
expected[2] = 0x1;
|
||||
expected[3] = 0x1;
|
||||
Encoding.ASCII.GetBytes("TestString", expected.Slice(4, 10));
|
||||
Encoding.ASCII.GetBytes("TestString", expected[4..14]);
|
||||
expected[14] = 0x0; // Null
|
||||
expected[15] = 0x2;
|
||||
expected[16] = 0x2;
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace Server.Tests.Buffers
|
|||
var strLength = fixedLength > -1 ? Math.Min(value.Length, fixedLength) : value.Length;
|
||||
var chars = value.AsSpan(0, strLength);
|
||||
|
||||
var writer = new CircularBufferWriter(buffer.SliceToLength(firstSize), buffer.Slice(firstSize));
|
||||
var writer = new CircularBufferWriter(buffer[..firstSize], buffer[firstSize..]);
|
||||
writer.Seek(offset, SeekOrigin.Begin);
|
||||
writer.WriteString(chars, encoding);
|
||||
|
||||
|
|
@ -63,11 +63,11 @@ namespace Server.Tests.Buffers
|
|||
{
|
||||
Span<byte> testEmpty = stackalloc byte[offset];
|
||||
testEmpty.Clear();
|
||||
AssertThat.Equal(buffer.SliceToLength(offset), testEmpty);
|
||||
AssertThat.Equal(buffer[..offset], testEmpty);
|
||||
}
|
||||
|
||||
Span<byte> expectedStr = stackalloc byte[encoding.GetByteCount(chars)];
|
||||
encoding.GetBytes(chars, expectedStr.Slice(0));
|
||||
encoding.GetBytes(chars, expectedStr[..]);
|
||||
|
||||
AssertThat.Equal(buffer.Slice(offset, expectedStr.Length), expectedStr);
|
||||
offset += expectedStr.Length;
|
||||
|
|
@ -76,7 +76,7 @@ namespace Server.Tests.Buffers
|
|||
{
|
||||
Span<byte> testEmpty = stackalloc byte[buffer.Length - offset];
|
||||
testEmpty.Clear();
|
||||
AssertThat.Equal(buffer.Slice(offset), testEmpty);
|
||||
AssertThat.Equal(buffer[offset..], testEmpty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,14 +101,14 @@ namespace Server.Tests
|
|||
{
|
||||
while (v.Length >= startIndex)
|
||||
{
|
||||
list.Add(v.Substring(0, startIndex));
|
||||
list.Add(v[..startIndex]);
|
||||
|
||||
if (list.Count == maxLines)
|
||||
{
|
||||
return list;
|
||||
}
|
||||
|
||||
v = v.Substring(startIndex);
|
||||
v = v[startIndex..];
|
||||
}
|
||||
|
||||
current = v;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue