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
|
|
@ -262,7 +262,7 @@ namespace Server
|
|||
for (var j = 0; j < alias.Aliases.Length; j++)
|
||||
{
|
||||
var fullName = alias.Aliases[j];
|
||||
var name = fullName.Substring(fullName.LastIndexOf('.') + 1);
|
||||
var name = fullName[(fullName.LastIndexOf('.') + 1)..];
|
||||
addToRefs(i, fullName, nameMap);
|
||||
addToRefs(i, fullName.ToLower(), nameMapInsensitive);
|
||||
addToRefs(i, name, nameMap);
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ namespace System.Buffers
|
|||
|
||||
if (_second.Length > 0)
|
||||
{
|
||||
_second.CopyTo(bytes.Slice(_first.Length));
|
||||
_second.CopyTo(bytes[_first.Length..]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,13 +102,13 @@ namespace Server.Network
|
|||
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadInt16BigEndian(_first.Slice(Position), out value))
|
||||
if (!BinaryPrimitives.TryReadInt16BigEndian(_first[Position..], out value))
|
||||
{
|
||||
// Not enough space. Split the spans
|
||||
return (short)((ReadByte() >> 8) | ReadByte());
|
||||
}
|
||||
}
|
||||
else if (!BinaryPrimitives.TryReadInt16BigEndian(_second.Slice(Position - _first.Length), out value))
|
||||
else if (!BinaryPrimitives.TryReadInt16BigEndian(_second[(Position - _first.Length)..], out value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -124,13 +124,13 @@ namespace Server.Network
|
|||
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadUInt16BigEndian(_first.Slice(Position), out value))
|
||||
if (!BinaryPrimitives.TryReadUInt16BigEndian(_first[Position..], out value))
|
||||
{
|
||||
// Not enough space. Split the spans
|
||||
return (ushort)((ReadByte() >> 8) | ReadByte());
|
||||
}
|
||||
}
|
||||
else if (!BinaryPrimitives.TryReadUInt16BigEndian(_second.Slice(Position - _first.Length), out value))
|
||||
else if (!BinaryPrimitives.TryReadUInt16BigEndian(_second[(Position - _first.Length)..], out value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -146,13 +146,13 @@ namespace Server.Network
|
|||
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadInt32BigEndian(_first.Slice(Position), out value))
|
||||
if (!BinaryPrimitives.TryReadInt32BigEndian(_first[Position..], out value))
|
||||
{
|
||||
// Not enough space. Split the spans
|
||||
return (ReadByte() >> 24) | (ReadByte() >> 16) | (ReadByte() >> 8) | ReadByte();
|
||||
}
|
||||
}
|
||||
else if (!BinaryPrimitives.TryReadInt32BigEndian(_second.Slice(Position - _first.Length), out value))
|
||||
else if (!BinaryPrimitives.TryReadInt32BigEndian(_second[(Position - _first.Length)..], out value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -168,13 +168,13 @@ namespace Server.Network
|
|||
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadUInt32BigEndian(_first.Slice(Position), out value))
|
||||
if (!BinaryPrimitives.TryReadUInt32BigEndian(_first[Position..], out value))
|
||||
{
|
||||
// Not enough space. Split the spans
|
||||
return (uint)((ReadByte() >> 24) | (ReadByte() >> 16) | (ReadByte() >> 8) | ReadByte());
|
||||
}
|
||||
}
|
||||
else if (!BinaryPrimitives.TryReadUInt32BigEndian(_second.Slice(Position - _first.Length), out value))
|
||||
else if (!BinaryPrimitives.TryReadUInt32BigEndian(_second[(Position - _first.Length)..], out value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -190,7 +190,7 @@ namespace Server.Network
|
|||
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadInt64BigEndian(_first.Slice(Position), out value))
|
||||
if (!BinaryPrimitives.TryReadInt64BigEndian(_first[Position..], out value))
|
||||
{
|
||||
// Not enough space. Split the spans
|
||||
return ((long)ReadByte() >> 56) |
|
||||
|
|
@ -203,7 +203,7 @@ namespace Server.Network
|
|||
ReadByte();
|
||||
}
|
||||
}
|
||||
else if (!BinaryPrimitives.TryReadInt64BigEndian(_second.Slice(Position - _first.Length), out value))
|
||||
else if (!BinaryPrimitives.TryReadInt64BigEndian(_second[(Position - _first.Length)..], out value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ namespace Server.Network
|
|||
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadUInt64BigEndian(_first.Slice(Position), out value))
|
||||
if (!BinaryPrimitives.TryReadUInt64BigEndian(_first[Position..], out value))
|
||||
{
|
||||
// Not enough space. Split the spans
|
||||
return ((ulong)ReadByte() >> 56) |
|
||||
|
|
@ -232,7 +232,7 @@ namespace Server.Network
|
|||
ReadByte();
|
||||
}
|
||||
}
|
||||
else if (!BinaryPrimitives.TryReadUInt64BigEndian(_second.Slice(Position - _first.Length), out value))
|
||||
else if (!BinaryPrimitives.TryReadUInt64BigEndian(_second[(Position - _first.Length)..], out value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -284,15 +284,15 @@ namespace Server.Network
|
|||
}
|
||||
else
|
||||
{
|
||||
index = _second.SliceToLength(remaining).IndexOfTerminator(sizeT);
|
||||
index = _second[..remaining].IndexOfTerminator(sizeT);
|
||||
|
||||
int secondLength = index < 0 ? remaining : index;
|
||||
int length = firstLength + secondLength;
|
||||
|
||||
// Assume no strings should be too long for the stack
|
||||
Span<byte> bytes = stackalloc byte[length];
|
||||
_first.Slice(Position).CopyTo(bytes);
|
||||
_second.SliceToLength(secondLength).CopyTo(bytes.Slice(firstLength));
|
||||
_first[Position..].CopyTo(bytes);
|
||||
_second[..secondLength].CopyTo(bytes[firstLength..]);
|
||||
|
||||
Position += length + (index >= 0 ? sizeT : 0);
|
||||
return TextEncoding.GetString(bytes, encoding, safeString);
|
||||
|
|
@ -309,7 +309,7 @@ namespace Server.Network
|
|||
|
||||
if (index >= 0)
|
||||
{
|
||||
span = span.SliceToLength(index);
|
||||
span = span[..index];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -388,7 +388,7 @@ namespace Server.Network
|
|||
return false;
|
||||
}
|
||||
|
||||
return _second.Length <= 0 || _second.TryCopyTo(bytes.Slice(_first.Length));
|
||||
return _second.Length <= 0 || _second.TryCopyTo(bytes[_first.Length..]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ namespace System.Buffers
|
|||
{
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryWriteInt16BigEndian(_first.Slice(Position), value))
|
||||
if (!BinaryPrimitives.TryWriteInt16BigEndian(_first[Position..], value))
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
@ -102,7 +102,7 @@ namespace System.Buffers
|
|||
Position += 2;
|
||||
}
|
||||
}
|
||||
else if (BinaryPrimitives.TryWriteInt16BigEndian(_second.Slice(Position - _first.Length), value))
|
||||
else if (BinaryPrimitives.TryWriteInt16BigEndian(_second[(Position - _first.Length)..], value))
|
||||
{
|
||||
Position += 2;
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ namespace System.Buffers
|
|||
{
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryWriteUInt16BigEndian(_first.Slice(Position), value))
|
||||
if (!BinaryPrimitives.TryWriteUInt16BigEndian(_first[Position..], value))
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
@ -132,7 +132,7 @@ namespace System.Buffers
|
|||
Position += 2;
|
||||
}
|
||||
}
|
||||
else if (BinaryPrimitives.TryWriteUInt16BigEndian(_second.Slice(Position - _first.Length), value))
|
||||
else if (BinaryPrimitives.TryWriteUInt16BigEndian(_second[(Position - _first.Length)..], value))
|
||||
{
|
||||
Position += 2;
|
||||
}
|
||||
|
|
@ -147,7 +147,7 @@ namespace System.Buffers
|
|||
{
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryWriteInt32BigEndian(_first.Slice(Position), value))
|
||||
if (!BinaryPrimitives.TryWriteInt32BigEndian(_first[Position..], value))
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
@ -164,7 +164,7 @@ namespace System.Buffers
|
|||
Position += 4;
|
||||
}
|
||||
}
|
||||
else if (BinaryPrimitives.TryWriteInt32BigEndian(_second.Slice(Position - _first.Length), value))
|
||||
else if (BinaryPrimitives.TryWriteInt32BigEndian(_second[(Position - _first.Length)..], value))
|
||||
{
|
||||
Position += 4;
|
||||
}
|
||||
|
|
@ -179,7 +179,7 @@ namespace System.Buffers
|
|||
{
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryWriteInt32LittleEndian(_first.Slice(Position), value))
|
||||
if (!BinaryPrimitives.TryWriteInt32LittleEndian(_first[Position..], value))
|
||||
{
|
||||
if (!BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
@ -196,7 +196,7 @@ namespace System.Buffers
|
|||
Position += 4;
|
||||
}
|
||||
}
|
||||
else if (BinaryPrimitives.TryWriteInt32LittleEndian(_second.Slice(Position - _first.Length), value))
|
||||
else if (BinaryPrimitives.TryWriteInt32LittleEndian(_second[(Position - _first.Length)..], value))
|
||||
{
|
||||
Position += 4;
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ namespace System.Buffers
|
|||
{
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryWriteUInt32BigEndian(_first.Slice(Position), value))
|
||||
if (!BinaryPrimitives.TryWriteUInt32BigEndian(_first[Position..], value))
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
@ -231,7 +231,7 @@ namespace System.Buffers
|
|||
Position += 4;
|
||||
}
|
||||
}
|
||||
else if (BinaryPrimitives.TryWriteUInt32BigEndian(_second.Slice(Position - _first.Length), value))
|
||||
else if (BinaryPrimitives.TryWriteUInt32BigEndian(_second[(Position - _first.Length)..], value))
|
||||
{
|
||||
Position += 4;
|
||||
}
|
||||
|
|
@ -246,7 +246,7 @@ namespace System.Buffers
|
|||
{
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryWriteUInt32LittleEndian(_first.Slice(Position), value))
|
||||
if (!BinaryPrimitives.TryWriteUInt32LittleEndian(_first[Position..], value))
|
||||
{
|
||||
if (!BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
@ -263,7 +263,7 @@ namespace System.Buffers
|
|||
Position += 4;
|
||||
}
|
||||
}
|
||||
else if (BinaryPrimitives.TryWriteUInt32LittleEndian(_second.Slice(Position - _first.Length), value))
|
||||
else if (BinaryPrimitives.TryWriteUInt32LittleEndian(_second[(Position - _first.Length)..], value))
|
||||
{
|
||||
Position += 4;
|
||||
}
|
||||
|
|
@ -281,7 +281,7 @@ namespace System.Buffers
|
|||
{
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryWriteInt64BigEndian(_first.Slice(Position), value))
|
||||
if (!BinaryPrimitives.TryWriteInt64BigEndian(_first[Position..], value))
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
@ -303,7 +303,7 @@ namespace System.Buffers
|
|||
Position += 8;
|
||||
}
|
||||
}
|
||||
else if (BinaryPrimitives.TryWriteInt64BigEndian(_second.Slice(Position - _first.Length), value))
|
||||
else if (BinaryPrimitives.TryWriteInt64BigEndian(_second[(Position - _first.Length)..], value))
|
||||
{
|
||||
Position += 8;
|
||||
}
|
||||
|
|
@ -321,7 +321,7 @@ namespace System.Buffers
|
|||
{
|
||||
if (Position < _first.Length)
|
||||
{
|
||||
if (!BinaryPrimitives.TryWriteUInt64BigEndian(_first.Slice(Position), value))
|
||||
if (!BinaryPrimitives.TryWriteUInt64BigEndian(_first[Position..], value))
|
||||
{
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
|
|
@ -342,7 +342,7 @@ namespace System.Buffers
|
|||
Position += 8;
|
||||
}
|
||||
}
|
||||
else if (BinaryPrimitives.TryWriteUInt64BigEndian(_second.Slice(Position - _first.Length), value))
|
||||
else if (BinaryPrimitives.TryWriteUInt64BigEndian(_second[(Position - _first.Length)..], value))
|
||||
{
|
||||
Position += 8;
|
||||
}
|
||||
|
|
@ -363,15 +363,15 @@ namespace System.Buffers
|
|||
if (Position < _first.Length)
|
||||
{
|
||||
var sz = Math.Min(buffer.Length, _first.Length - Position);
|
||||
buffer.SliceToLength(sz).CopyTo(_first.Slice(Position));
|
||||
buffer[..sz].CopyTo(_first[Position..]);
|
||||
if (sz < buffer.Length)
|
||||
{
|
||||
buffer.Slice(sz).CopyTo(_second);
|
||||
buffer[sz..].CopyTo(_second);
|
||||
}
|
||||
}
|
||||
else if (Position < Length)
|
||||
{
|
||||
buffer.CopyTo(_second.Slice(Position - _first.Length));
|
||||
buffer.CopyTo(_second[(Position - _first.Length)..]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -398,7 +398,7 @@ namespace System.Buffers
|
|||
if (Position < _first.Length)
|
||||
{
|
||||
count = Math.Min(_first.Length - Position, byteCount);
|
||||
bytes.SliceToLength(count).CopyTo(_first.Slice(Position));
|
||||
bytes[..count].CopyTo(_first[Position..]);
|
||||
byteCount -= count;
|
||||
Position += count;
|
||||
}
|
||||
|
|
@ -409,7 +409,7 @@ namespace System.Buffers
|
|||
|
||||
if (byteCount > 0)
|
||||
{
|
||||
bytes.Slice(count).CopyTo(_second.Slice(Math.Max(0, Position - _first.Length)));
|
||||
bytes[count..].CopyTo(_second[Math.Max(0, Position - _first.Length)..]);
|
||||
Position += byteCount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public short ReadInt16()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadInt16BigEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadInt16BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public short ReadInt16LE()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadInt16LittleEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadInt16LittleEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -82,7 +82,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ushort ReadUInt16()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadUInt16BigEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadUInt16BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ushort ReadUInt16LE()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadUInt16LittleEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadUInt16LittleEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int ReadInt32()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadInt32BigEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadInt32BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -118,7 +118,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public uint ReadUInt32()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadUInt32BigEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadUInt32BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public uint ReadUInt32LE()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadUInt32LittleEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadUInt32LittleEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public long ReadInt64()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadInt64BigEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadInt64BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
@ -154,7 +154,7 @@ namespace System.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ulong ReadUInt64()
|
||||
{
|
||||
if (!BinaryPrimitives.TryReadUInt64BigEndian(_buffer.Slice(Position), out var value))
|
||||
if (!BinaryPrimitives.TryReadUInt64BigEndian(_buffer[Position..], out var value))
|
||||
{
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace System.Buffers
|
|||
|
||||
public int Capacity => _buffer.Length;
|
||||
|
||||
public ReadOnlySpan<byte> Span => _buffer.SliceToLength(Position);
|
||||
public ReadOnlySpan<byte> Span => _buffer[..Position];
|
||||
|
||||
public Span<byte> RawBuffer => _buffer;
|
||||
|
||||
|
|
@ -119,7 +119,7 @@ namespace System.Buffers
|
|||
var newSize = Math.Max(BytesWritten + additionalCapacity, _buffer.Length * 2);
|
||||
byte[] poolArray = ArrayPool<byte>.Shared.Rent(newSize);
|
||||
|
||||
_buffer.SliceToLength(BytesWritten).CopyTo(poolArray);
|
||||
_buffer[..BytesWritten].CopyTo(poolArray);
|
||||
|
||||
byte[] toReturn = _arrayToReturnToPool;
|
||||
_buffer = _arrayToReturnToPool = poolArray;
|
||||
|
|
@ -183,7 +183,7 @@ namespace System.Buffers
|
|||
public void Write(short value)
|
||||
{
|
||||
GrowIfNeeded(2);
|
||||
BinaryPrimitives.WriteInt16BigEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteInt16BigEndian(_buffer[_position..], value);
|
||||
Position += 2;
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +191,7 @@ namespace System.Buffers
|
|||
public void WriteLE(short value)
|
||||
{
|
||||
GrowIfNeeded(2);
|
||||
BinaryPrimitives.WriteInt16LittleEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteInt16LittleEndian(_buffer[_position..], value);
|
||||
Position += 2;
|
||||
}
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ namespace System.Buffers
|
|||
public void Write(ushort value)
|
||||
{
|
||||
GrowIfNeeded(2);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(_buffer[_position..], value);
|
||||
Position += 2;
|
||||
}
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ namespace System.Buffers
|
|||
public void WriteLE(ushort value)
|
||||
{
|
||||
GrowIfNeeded(2);
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteUInt16LittleEndian(_buffer[_position..], value);
|
||||
Position += 2;
|
||||
}
|
||||
|
||||
|
|
@ -215,7 +215,7 @@ namespace System.Buffers
|
|||
public void Write(int value)
|
||||
{
|
||||
GrowIfNeeded(4);
|
||||
BinaryPrimitives.WriteInt32BigEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteInt32BigEndian(_buffer[_position..], value);
|
||||
Position += 4;
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +223,7 @@ namespace System.Buffers
|
|||
public void WriteLE(int value)
|
||||
{
|
||||
GrowIfNeeded(4);
|
||||
BinaryPrimitives.WriteInt32LittleEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteInt32LittleEndian(_buffer[_position..], value);
|
||||
Position += 4;
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +231,7 @@ namespace System.Buffers
|
|||
public void Write(uint value)
|
||||
{
|
||||
GrowIfNeeded(4);
|
||||
BinaryPrimitives.WriteUInt32BigEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteUInt32BigEndian(_buffer[_position..], value);
|
||||
Position += 4;
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +239,7 @@ namespace System.Buffers
|
|||
public void WriteLE(uint value)
|
||||
{
|
||||
GrowIfNeeded(4);
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteUInt32LittleEndian(_buffer[_position..], value);
|
||||
Position += 4;
|
||||
}
|
||||
|
||||
|
|
@ -247,7 +247,7 @@ namespace System.Buffers
|
|||
public void Write(long value)
|
||||
{
|
||||
GrowIfNeeded(8);
|
||||
BinaryPrimitives.WriteInt64BigEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteInt64BigEndian(_buffer[_position..], value);
|
||||
Position += 8;
|
||||
}
|
||||
|
||||
|
|
@ -255,7 +255,7 @@ namespace System.Buffers
|
|||
public void Write(ulong value)
|
||||
{
|
||||
GrowIfNeeded(8);
|
||||
BinaryPrimitives.WriteUInt64BigEndian(_buffer.Slice(_position), value);
|
||||
BinaryPrimitives.WriteUInt64BigEndian(_buffer[_position..], value);
|
||||
Position += 8;
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ namespace System.Buffers
|
|||
{
|
||||
var count = buffer.Length;
|
||||
GrowIfNeeded(count);
|
||||
buffer.CopyTo(_buffer.Slice(_position));
|
||||
buffer.CopyTo(_buffer[_position..]);
|
||||
Position += count;
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +293,7 @@ namespace System.Buffers
|
|||
|
||||
GrowIfNeeded(byteCount);
|
||||
|
||||
var bytesWritten = encoding.GetBytes(src, _buffer.Slice(_position));
|
||||
var bytesWritten = encoding.GetBytes(src, _buffer[_position..]);
|
||||
Position += bytesWritten;
|
||||
|
||||
if (fixedLength > -1)
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ namespace Server.Buffers
|
|||
public ref char this[int index] => ref _chars[index];
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override string ToString() => _chars.SliceToLength(_length).ToString();
|
||||
public override string ToString() => _chars[.._length].ToString();
|
||||
|
||||
/// <summary>Returns the underlying storage of the builder.</summary>
|
||||
public Span<char> RawChars => _chars;
|
||||
|
|
@ -102,14 +102,14 @@ namespace Server.Buffers
|
|||
EnsureCapacity(_length + 1);
|
||||
_chars[_length] = '\0';
|
||||
}
|
||||
return _chars.SliceToLength(_length);
|
||||
return _chars[.._length];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ReadOnlySpan<char> AsSpan() => _chars.SliceToLength(_length);
|
||||
public ReadOnlySpan<char> AsSpan() => _chars[.._length];
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ReadOnlySpan<char> AsSpan(int start) => _chars.Slice(start, _length - start);
|
||||
public ReadOnlySpan<char> AsSpan(int start) => _chars[start..];
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ReadOnlySpan<char> AsSpan(int start, int length) => _chars.Slice(start, length);
|
||||
|
|
@ -117,7 +117,7 @@ namespace Server.Buffers
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool TryCopyTo(Span<char> destination, out int charsWritten)
|
||||
{
|
||||
if (_chars.SliceToLength(_length).TryCopyTo(destination))
|
||||
if (_chars[.._length].TryCopyTo(destination))
|
||||
{
|
||||
charsWritten = _length;
|
||||
return true;
|
||||
|
|
@ -136,7 +136,7 @@ namespace Server.Buffers
|
|||
}
|
||||
|
||||
int remaining = _length - index;
|
||||
_chars.Slice(index, remaining).CopyTo(_chars.Slice(index + count));
|
||||
_chars.Slice(index, remaining).CopyTo(_chars[(index + count)..]);
|
||||
_chars.Slice(index, count).Fill(value);
|
||||
_length += count;
|
||||
}
|
||||
|
|
@ -157,8 +157,8 @@ namespace Server.Buffers
|
|||
}
|
||||
|
||||
int remaining = _length - index;
|
||||
_chars.Slice(index, remaining).CopyTo(_chars.Slice(index + count));
|
||||
s.AsSpan().CopyTo(_chars.Slice(index));
|
||||
_chars.Slice(index, remaining).CopyTo(_chars[(index + count)..]);
|
||||
s.AsSpan().CopyTo(_chars[index..]);
|
||||
_length += count;
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +208,7 @@ namespace Server.Buffers
|
|||
return;
|
||||
}
|
||||
|
||||
fixed (char* buffer = _chars.Slice(pos))
|
||||
fixed (char* buffer = _chars[pos..])
|
||||
{
|
||||
char* p = buffer + bufferLength;
|
||||
do
|
||||
|
|
@ -271,7 +271,7 @@ namespace Server.Buffers
|
|||
Grow(s.Length);
|
||||
}
|
||||
|
||||
s.AsSpan().CopyTo(_chars.Slice(pos));
|
||||
s.AsSpan().CopyTo(_chars[pos..]);
|
||||
_length += s.Length;
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +317,7 @@ namespace Server.Buffers
|
|||
Grow(value.Length);
|
||||
}
|
||||
|
||||
value.CopyTo(_chars.Slice(_length));
|
||||
value.CopyTo(_chars[_length..]);
|
||||
_length += value.Length;
|
||||
}
|
||||
|
||||
|
|
@ -355,7 +355,7 @@ namespace Server.Buffers
|
|||
{
|
||||
char[] poolArray = ArrayPool<char>.Shared.Rent(Math.Max(_length + additionalCapacityBeyondPos, _chars.Length * 2));
|
||||
|
||||
_chars.SliceToLength(_length).CopyTo(poolArray);
|
||||
_chars[.._length].CopyTo(poolArray);
|
||||
|
||||
char[] toReturn = _arrayToReturnToPool;
|
||||
_chars = _arrayToReturnToPool = poolArray;
|
||||
|
|
@ -404,7 +404,7 @@ namespace Server.Buffers
|
|||
var chr = slice[indexOf];
|
||||
|
||||
slice[indexOf] = newChars[oldChars.IndexOf(chr)];
|
||||
slice = slice.Slice(indexOf + 1);
|
||||
slice = slice[(indexOf + 1)..];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -433,7 +433,7 @@ namespace Server.Buffers
|
|||
}
|
||||
|
||||
slice[indexOf] = newChar;
|
||||
slice = slice.Slice(indexOf + 1);
|
||||
slice = slice[(indexOf + 1)..];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -457,16 +457,16 @@ namespace Server.Buffers
|
|||
|
||||
if (startIndex == 0)
|
||||
{
|
||||
_chars = _chars.Slice(length);
|
||||
_chars = _chars[length..];
|
||||
}
|
||||
else if (startIndex + length == _length)
|
||||
{
|
||||
_chars = _chars.SliceToLength(startIndex);
|
||||
_chars = _chars[..startIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Somewhere in the middle, this will be slow
|
||||
_chars.Slice(startIndex + length).CopyTo(_chars.Slice(startIndex));
|
||||
_chars[(startIndex + length)..].CopyTo(_chars[startIndex..]);
|
||||
}
|
||||
|
||||
_length -= length;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ namespace Server
|
|||
br3++;
|
||||
}
|
||||
|
||||
Major = Utility.ToInt32(fmt.Substring(0, br1));
|
||||
Major = Utility.ToInt32(fmt.AsSpan()[..br1]);
|
||||
Minor = Utility.ToInt32(fmt.Substring(br1 + 1, br2 - br1 - 1));
|
||||
Revision = Utility.ToInt32(fmt.Substring(br2 + 1, br3 - br2 - 1));
|
||||
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ namespace Server
|
|||
|
||||
if (type != MessageType.Command)
|
||||
{
|
||||
text = text.Substring(Prefix.Length);
|
||||
text = text[Prefix.Length..];
|
||||
}
|
||||
|
||||
var indexOf = text.IndexOfOrdinal(' ');
|
||||
|
|
@ -268,9 +268,9 @@ namespace Server
|
|||
|
||||
if (indexOf >= 0)
|
||||
{
|
||||
argString = text.Substring(indexOf + 1);
|
||||
argString = text[(indexOf + 1)..];
|
||||
|
||||
command = text.Substring(0, indexOf);
|
||||
command = text[..indexOf];
|
||||
args = Split(argString);
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1150,7 +1150,7 @@ namespace Server
|
|||
var length = OutgoingEntityPackets.CreateWorldEntity(hsWorldItem, this, true);
|
||||
if (length != hsWorldItem.Length)
|
||||
{
|
||||
hsWorldItem = hsWorldItem.SliceToLength(length);
|
||||
hsWorldItem = hsWorldItem[..length];
|
||||
}
|
||||
|
||||
SendInfoTo(state, hsWorldItem, opl);
|
||||
|
|
@ -1160,7 +1160,7 @@ namespace Server
|
|||
var length = OutgoingEntityPackets.CreateWorldEntity(saWorldItem, this, false);
|
||||
if (length != saWorldItem.Length)
|
||||
{
|
||||
saWorldItem = saWorldItem.SliceToLength(length);
|
||||
saWorldItem = saWorldItem[..length];
|
||||
}
|
||||
|
||||
SendInfoTo(state, saWorldItem, opl);
|
||||
|
|
@ -1170,7 +1170,7 @@ namespace Server
|
|||
var length = OutgoingItemPackets.CreateWorldItem(oldWorldItem, this);
|
||||
if (length != oldWorldItem.Length)
|
||||
{
|
||||
oldWorldItem = oldWorldItem.SliceToLength(length);
|
||||
oldWorldItem = oldWorldItem[..length];
|
||||
}
|
||||
|
||||
SendInfoTo(state, oldWorldItem, opl);
|
||||
|
|
@ -3330,7 +3330,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
state.Send(buffer);
|
||||
|
|
@ -3364,7 +3364,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
state.Send(buffer);
|
||||
|
|
|
|||
|
|
@ -5792,7 +5792,7 @@ namespace Server
|
|||
|
||||
if (length != regBuffer.Length)
|
||||
{
|
||||
regBuffer = regBuffer.SliceToLength(length); // Adjust to the actual size
|
||||
regBuffer = regBuffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
heard.OnSpeech(regArgs);
|
||||
|
|
@ -5806,7 +5806,7 @@ namespace Server
|
|||
|
||||
if (length != mutBuffer.Length)
|
||||
{
|
||||
mutBuffer = mutBuffer.SliceToLength(length); // Adjust to the actual size
|
||||
mutBuffer = mutBuffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
heard.OnSpeech(mutatedArgs);
|
||||
|
|
@ -9155,7 +9155,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
state.Send(buffer);
|
||||
|
|
@ -9186,7 +9186,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
state.Send(buffer);
|
||||
|
|
@ -9220,7 +9220,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
state.Send(buffer);
|
||||
|
|
@ -9268,7 +9268,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
state.Send(buffer);
|
||||
|
|
@ -9299,7 +9299,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
state.Send(buffer);
|
||||
|
|
|
|||
|
|
@ -40,12 +40,6 @@ namespace Server.Network
|
|||
writer.Seek(0, SeekOrigin.End);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Span<T> SliceToLength<T>(this Span<T> span, int length) => span.Slice(0, length);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ReadOnlySpan<T> SliceToLength<T>(this ReadOnlySpan<T> span, int length) => span.Slice(0, length);
|
||||
|
||||
// If LOCAL INIT is off, then stack/heap allocations have garbage data
|
||||
// Initializes the first byte (Packet ID) so it can be used as a flag.
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ namespace Server.Network
|
|||
OutgoingEntityPackets.CreateWorldEntity(buffer, item, ns.HighSeas) :
|
||||
CreateWorldItem(buffer, item);
|
||||
|
||||
ns.Send(buffer.SliceToLength(length));
|
||||
ns.Send(buffer[..length]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Server.Network
|
|||
buffer, serial, graphic, type, hue, font, number, name, args
|
||||
);
|
||||
|
||||
ns.Send(buffer.SliceToLength(length));
|
||||
ns.Send(buffer[..length]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
@ -102,7 +102,7 @@ namespace Server.Network
|
|||
buffer, serial, graphic, type, hue, font, number, name, affixType, affix, args
|
||||
);
|
||||
|
||||
ns.Send(buffer.SliceToLength(length));
|
||||
ns.Send(buffer[..length]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
@ -171,7 +171,7 @@ namespace Server.Network
|
|||
text
|
||||
);
|
||||
|
||||
ns.Send(buffer.SliceToLength(length));
|
||||
ns.Send(buffer[..length]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
|
|
|||
|
|
@ -470,7 +470,7 @@ namespace Server.Network
|
|||
}
|
||||
|
||||
var length = CreateMobileStatus(buffer, beholder, beheld, version, beheld.CanBeRenamedBy(beholder));
|
||||
ns.Send(buffer.SliceToLength(length));
|
||||
ns.Send(buffer[..length]);
|
||||
}
|
||||
|
||||
public static int CreateMobileStatus(
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@ namespace Server.Network
|
|||
{
|
||||
if (!_finished)
|
||||
{
|
||||
BinaryPrimitives.WriteUInt16BigEndian(_bytes.Slice(1, 2), (ushort)Length);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(_bytes.Slice(3, 2), (ushort)_count);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(_bytes[1..3], (ushort)Length);
|
||||
BinaryPrimitives.WriteUInt16BigEndian(_bytes[3..5], (ushort)_count);
|
||||
}
|
||||
|
||||
return _bytes.SliceToLength(Length);
|
||||
return _bytes[..Length];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
|
|
@ -70,7 +70,7 @@ namespace Server.Network
|
|||
Grow(bytesNeeded);
|
||||
}
|
||||
|
||||
return _bytes.Slice(Length);
|
||||
return _bytes[Length..];
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
|
|
@ -91,7 +91,7 @@ namespace Server.Network
|
|||
var newLength = Math.Max(Length + additionalCapacityBeyondPos, _bytes.Length * 2);
|
||||
byte[] poolArray = ArrayPool<byte>.Shared.Rent(newLength);
|
||||
|
||||
_bytes.SliceToLength(Length).CopyTo(poolArray);
|
||||
_bytes[..Length].CopyTo(poolArray);
|
||||
|
||||
byte[] toReturn = _arrayToReturnToPool;
|
||||
_bytes = _arrayToReturnToPool = poolArray;
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ namespace Server
|
|||
|
||||
int index = buffer.IndexOfTerminator(sizeT);
|
||||
|
||||
var span = buffer.SliceToLength(index < 0 ? size : index);
|
||||
var span = buffer[..(index < 0 ? size : index)];
|
||||
_position += isFixedLength || index < 0 ? size : index + sizeT;
|
||||
return TextEncoding.GetString(span, encoding, safeString);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ namespace Server
|
|||
Span<byte> stack = stackalloc byte[16];
|
||||
value.TryWriteBytes(stack, out var bytesWritten);
|
||||
Write((byte)bytesWritten);
|
||||
Write(stack.SliceToLength(bytesWritten));
|
||||
Write(stack[..bytesWritten]);
|
||||
}
|
||||
|
||||
public void Write(TimeSpan value)
|
||||
|
|
@ -441,7 +441,7 @@ namespace Server
|
|||
charsLeft -= charCount;
|
||||
current += charCount;
|
||||
|
||||
Write(span.SliceToLength(bytesWritten));
|
||||
Write(span[..bytesWritten]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ namespace Server
|
|||
throw new OutOfMemoryException(nameof(buffer));
|
||||
}
|
||||
|
||||
sliced.SliceToLength(indexOf).CopyTo(buffer.Slice(size));
|
||||
sliced[..indexOf].CopyTo(buffer[size..]);
|
||||
size += indexOf;
|
||||
|
||||
if (indexOf == sliced.Length)
|
||||
|
|
@ -66,7 +66,7 @@ namespace Server
|
|||
break;
|
||||
}
|
||||
|
||||
sliced = sliced.Slice(indexOf + 1);
|
||||
sliced = sliced[(indexOf + 1)..];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +97,7 @@ namespace Server
|
|||
|
||||
a.Remove(b, comparison, span, out var size);
|
||||
|
||||
var str = span.SliceToLength(size).ToString();
|
||||
var str = span[..size].ToString();
|
||||
|
||||
if (chrs != null)
|
||||
{
|
||||
|
|
@ -138,7 +138,7 @@ namespace Server
|
|||
// Special case for titles - words that don't get capitalized
|
||||
if (sliced.InsensitiveStartsWith("the "))
|
||||
{
|
||||
sliced = sliced.Slice(4);
|
||||
sliced = sliced[4..];
|
||||
index += 4;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ namespace Server
|
|||
break;
|
||||
}
|
||||
|
||||
sliced = sliced.Slice(indexOf + 1);
|
||||
sliced = sliced[(indexOf + 1)..];
|
||||
index += indexOf + 1;
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +183,7 @@ namespace Server
|
|||
|
||||
while (span.Length > 0)
|
||||
{
|
||||
var spaceIndex = span.Slice(lineLength).IndexOf(' ');
|
||||
var spaceIndex = span[lineLength..].IndexOf(' ');
|
||||
if (spaceIndex == -1)
|
||||
{
|
||||
spaceIndex = span.Length; // End of the string
|
||||
|
|
@ -193,13 +193,13 @@ namespace Server
|
|||
|
||||
if (newLineLength == perLine || newLineLength == span.Length)
|
||||
{
|
||||
list.Add(span.SliceToLength(newLineLength).ToString());
|
||||
list.Add(span[..newLineLength].ToString());
|
||||
if (list.Count == maxLines || newLineLength == span.Length)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
span = span.Slice(newLineLength + 1);
|
||||
span = span[(newLineLength + 1)..];
|
||||
lineLength = 0;
|
||||
}
|
||||
else if (newLineLength < perLine)
|
||||
|
|
@ -208,13 +208,13 @@ namespace Server
|
|||
}
|
||||
else if (lineLength > 0 && lineLength <= perLine)
|
||||
{
|
||||
list.Add(span.SliceToLength(lineLength - 1).ToString());
|
||||
list.Add(span[..(lineLength - 1)].ToString());
|
||||
if (list.Count == maxLines)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
span = span.Slice(lineLength);
|
||||
span = span[lineLength..];
|
||||
lineLength = spaceIndex;
|
||||
}
|
||||
else
|
||||
|
|
@ -236,7 +236,7 @@ namespace Server
|
|||
index += perLine;
|
||||
}
|
||||
|
||||
span = span.Slice(newLineLength - lineLength);
|
||||
span = span[(newLineLength - lineLength)..];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -387,7 +387,7 @@ namespace Server
|
|||
var sectionStart = 0;
|
||||
var hasCompressor = false;
|
||||
|
||||
var num = BinaryPrimitives.ReadUInt16BigEndian(ip.SliceToLength(2));
|
||||
var num = BinaryPrimitives.ReadUInt16BigEndian(ip[..2]);
|
||||
|
||||
for (int i = 0; i < end; i++)
|
||||
{
|
||||
|
|
@ -473,10 +473,10 @@ namespace Server
|
|||
// IPv4 matching at the end
|
||||
if (section == 6 && num == 0xFFFF)
|
||||
{
|
||||
var ipv4 = val.Slice(i + 1);
|
||||
var ipv4 = val[(i + 1)..];
|
||||
if (ipv4.Contains('.'))
|
||||
{
|
||||
return IPv4Match(ipv4, ip.Slice(ip.Length - 4), out valid);
|
||||
return IPv4Match(ipv4, ip[^4..], out valid);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -504,7 +504,7 @@ namespace Server
|
|||
|
||||
if (i + 1 < end)
|
||||
{
|
||||
var remainingColons = val.Slice(i + 1).Count(':');
|
||||
var remainingColons = val[(i + 1)..].Count(':');
|
||||
// double colon must be at least 2 sections
|
||||
// we need at least 1 section remaining out of 8
|
||||
// This means 8 - 2 would be 6 sections (5 colons)
|
||||
|
|
@ -972,7 +972,7 @@ namespace Server
|
|||
#pragma warning disable CA1806 // Do not ignore method results
|
||||
if (value.StartsWithOrdinal("0x"))
|
||||
{
|
||||
int.TryParse(value.Slice(2), NumberStyles.HexNumber, null, out i);
|
||||
int.TryParse(value[2..], NumberStyles.HexNumber, null, out i);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -990,7 +990,7 @@ namespace Server
|
|||
#pragma warning disable CA1806 // Do not ignore method results
|
||||
if (value.InsensitiveStartsWith("0x"))
|
||||
{
|
||||
uint.TryParse(value.Slice(2), NumberStyles.HexNumber, null, out i);
|
||||
uint.TryParse(value[2..], NumberStyles.HexNumber, null, out i);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1003,12 +1003,12 @@ namespace Server
|
|||
|
||||
public static bool ToInt32(ReadOnlySpan<char> value, out int i) =>
|
||||
value.InsensitiveStartsWith("0x")
|
||||
? int.TryParse(value.Slice(2), NumberStyles.HexNumber, null, out i)
|
||||
? int.TryParse(value[2..], NumberStyles.HexNumber, null, out i)
|
||||
: int.TryParse(value, out i);
|
||||
|
||||
public static bool ToUInt32(ReadOnlySpan<char> value, out uint i) =>
|
||||
value.InsensitiveStartsWith("0x")
|
||||
? uint.TryParse(value.Slice(2), NumberStyles.HexNumber, null, out i)
|
||||
? uint.TryParse(value[2..], NumberStyles.HexNumber, null, out i)
|
||||
: uint.TryParse(value, out i);
|
||||
|
||||
public static int GetXMLInt32(string intString, int defaultValue)
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
ns.Send(buffer);
|
||||
|
|
@ -211,7 +211,7 @@ namespace Server
|
|||
|
||||
if (length != buffer.Length)
|
||||
{
|
||||
buffer = buffer.SliceToLength(length); // Adjust to the actual size
|
||||
buffer = buffer[..length]; // Adjust to the actual size
|
||||
}
|
||||
|
||||
ns.Send(buffer);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue