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
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue