CellLayer, use span.

This commit is contained in:
Vapre
2026-02-07 21:50:12 +01:00
committed by Gustas Kažukauskas
parent 6b04dbc210
commit 0a933ba09c
3 changed files with 25 additions and 12 deletions

View File

@@ -40,19 +40,19 @@ namespace OpenRA
if (Size != anotherLayer.Size || GridType != anotherLayer.GridType)
throw new ArgumentException("Layers must have a matching size and shape (grid type).", nameof(anotherLayer));
Array.Copy(anotherLayer.Entries, Entries, Entries.Length);
anotherLayer.Entries.AsSpan().CopyTo(Entries);
}
/// <summary>Clears the layer contents with their default value.</summary>
public virtual void Clear()
{
Array.Clear(Entries, 0, Entries.Length);
Entries.AsSpan().Clear();
}
/// <summary>Clears the layer contents with a known value.</summary>
public virtual void Clear(T clearValue)
{
Array.Fill(Entries, clearValue);
Entries.AsSpan().Fill(clearValue);
}
public IEnumerator<T> GetEnumerator()
@@ -64,5 +64,15 @@ namespace OpenRA
{
return GetEnumerator();
}
public ReadOnlyMemory<T> AsReadOnlyMemory()
{
return Entries.AsMemory();
}
public Memory<T> AsMemory()
{
return Entries.AsMemory();
}
}
}

View File

@@ -55,14 +55,9 @@ namespace OpenRA
return Bounds.Contains(uv.U, uv.V);
}
public int IndexOf(T value, int startIndex)
{
return Array.IndexOf(Entries, value, startIndex);
}
public void SetAll(T value)
{
Array.Fill(Entries, value);
Entries.AsSpan().Fill(value);
}
}
}