fix: Cleans up core code (#1187)
**Only one functional change** * Fixes a bug in LogFactory where `Warning` is being logged as `Information` Non-functional changes: * Updates/Fixes copyright headers * Removes namespace scopes for core files. View with [whitespace off](https://github.com/modernuo/ModernUO/pull/1187/files?w=1).
This commit is contained in:
parent
0138d40bda
commit
f268d5d4e2
262 changed files with 28527 additions and 28646 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: CircularBuffer.cs *
|
||||
* *
|
||||
|
|
@ -13,128 +13,127 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
namespace System.Buffers
|
||||
namespace System.Buffers;
|
||||
|
||||
public readonly ref struct CircularBuffer<T>
|
||||
{
|
||||
public readonly ref struct CircularBuffer<T>
|
||||
private readonly Span<T> _first;
|
||||
private readonly Span<T> _second;
|
||||
|
||||
public int Length { get; }
|
||||
|
||||
public CircularBuffer(ArraySegment<T>[] buffers) : this(buffers[0], buffers[1])
|
||||
{
|
||||
private readonly Span<T> _first;
|
||||
private readonly Span<T> _second;
|
||||
}
|
||||
|
||||
public int Length { get; }
|
||||
public CircularBuffer(Span<T> first, Span<T> second)
|
||||
{
|
||||
_first = first;
|
||||
_second = second;
|
||||
Length = first.Length + second.Length;
|
||||
}
|
||||
|
||||
public CircularBuffer(ArraySegment<T>[] buffers) : this(buffers[0], buffers[1])
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
}
|
||||
|
||||
public CircularBuffer(Span<T> first, Span<T> second)
|
||||
{
|
||||
_first = first;
|
||||
_second = second;
|
||||
Length = first.Length + second.Length;
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get
|
||||
if (index < 0 || index > Length)
|
||||
{
|
||||
if (index < 0 || index > Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
return index < _first.Length ? _first[index] : _second[index - _first.Length];
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
set
|
||||
{
|
||||
if (index < 0 || index > Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
if (index < _first.Length)
|
||||
{
|
||||
_first[index] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_second[index - _first.Length] = value;
|
||||
}
|
||||
return index < _first.Length ? _first[index] : _second[index - _first.Length];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (index < 0 || index > Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
if (index < _first.Length)
|
||||
{
|
||||
_first[index] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
_second[index - _first.Length] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CopyFrom(ReadOnlySpan<T> bytes)
|
||||
public void CopyFrom(ReadOnlySpan<T> bytes)
|
||||
{
|
||||
var remaining = bytes.Length;
|
||||
var offset = 0;
|
||||
|
||||
if (remaining == 0)
|
||||
{
|
||||
var remaining = bytes.Length;
|
||||
var offset = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var buffer = i == 0 ? _first : _second;
|
||||
|
||||
if (buffer.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var sz = Math.Min(remaining, buffer.Length);
|
||||
bytes.Slice(offset, sz).CopyTo(buffer);
|
||||
|
||||
remaining -= sz;
|
||||
offset += sz;
|
||||
|
||||
if (remaining == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
var buffer = i == 0 ? _first : _second;
|
||||
|
||||
if (buffer.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var sz = Math.Min(remaining, buffer.Length);
|
||||
bytes.Slice(offset, sz).CopyTo(buffer);
|
||||
|
||||
remaining -= sz;
|
||||
offset += sz;
|
||||
|
||||
if (remaining == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
||||
public void CopyTo(Span<T> bytes)
|
||||
throw new OutOfMemoryException();
|
||||
}
|
||||
|
||||
public void CopyTo(Span<T> bytes)
|
||||
{
|
||||
if (bytes.Length < Length)
|
||||
{
|
||||
if (bytes.Length < Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(bytes));
|
||||
}
|
||||
|
||||
if (_first.Length > 0)
|
||||
{
|
||||
_first.CopyTo(bytes);
|
||||
}
|
||||
|
||||
if (_second.Length > 0)
|
||||
{
|
||||
_second.CopyTo(bytes[_first.Length..]);
|
||||
}
|
||||
throw new ArgumentOutOfRangeException(nameof(bytes));
|
||||
}
|
||||
|
||||
public CircularBuffer<T> Slice(int offset, int count)
|
||||
if (_first.Length > 0)
|
||||
{
|
||||
var firstCount = Math.Min(count, _first.Length - offset);
|
||||
var first = offset < _first.Length
|
||||
? _first.Slice(offset, firstCount)
|
||||
: Span<T>.Empty;
|
||||
|
||||
var secondCount = offset > _first.Length ? count : count - firstCount;
|
||||
var second = secondCount > 0 ? _second.Slice(Math.Max(0, offset - _first.Length), secondCount) : Span<T>.Empty;
|
||||
|
||||
return new CircularBuffer<T>(first, second);
|
||||
_first.CopyTo(bytes);
|
||||
}
|
||||
|
||||
public Span<T> GetSpan(int index)
|
||||
if (_second.Length > 0)
|
||||
{
|
||||
if (index is < 0 or > 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
return index == 0 ? _first : _second;
|
||||
_second.CopyTo(bytes[_first.Length..]);
|
||||
}
|
||||
}
|
||||
|
||||
public CircularBuffer<T> Slice(int offset, int count)
|
||||
{
|
||||
var firstCount = Math.Min(count, _first.Length - offset);
|
||||
var first = offset < _first.Length
|
||||
? _first.Slice(offset, firstCount)
|
||||
: Span<T>.Empty;
|
||||
|
||||
var secondCount = offset > _first.Length ? count : count - firstCount;
|
||||
var second = secondCount > 0 ? _second.Slice(Math.Max(0, offset - _first.Length), secondCount) : Span<T>.Empty;
|
||||
|
||||
return new CircularBuffer<T>(first, second);
|
||||
}
|
||||
|
||||
public Span<T> GetSpan(int index)
|
||||
{
|
||||
if (index is < 0 or > 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
}
|
||||
|
||||
return index == 0 ? _first : _second;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue