Adjust implementation

pull/16772/head
PascalSenn 2024-05-08 13:05:05 +02:00
parent 4a90602b94
commit 775647a7cf
2 changed files with 4 additions and 30 deletions

View File

@ -898,26 +898,5 @@ namespace Google.Protobuf.Collections
Assert.AreEqual(2, span[1]);
Assert.AreEqual(3, span[2]);
}
[Test]
public void Memory_Empty()
{
var list = new RepeatedField<int>();
var memory = list.Memory;
Assert.AreEqual(0, memory.Length);
}
[Test]
public void Memory_Access()
{
var list = new RepeatedField<int> { 1, 2, 3 };
var memory = list.Memory;
Assert.AreEqual(3, memory.Length);
Assert.AreEqual(1, memory.Span[0]);
Assert.AreEqual(2, memory.Span[1]);
Assert.AreEqual(3, memory.Span[2]);
}
}
}

View File

@ -41,20 +41,15 @@ namespace Google.Protobuf.Collections
/// Provides read-only access to the data of this <see cref="RepeatedField{T}"/>.
/// No data is copied so this is the most efficient way of accessing.
/// </summary>
/// <remarks>
/// Modifying the contents of the <see cref="RepeatedField{T}"/> while using the returned
/// <see cref="ReadOnlySpan{T}"/> can lead to undefined behavior.
/// </remarks>
public ReadOnlySpan<T> Span
{
get { return array.AsSpan(0, count); }
}
/// <summary>
/// Provides read-only access to the data of this <see cref="RepeatedField{T}"/>.
/// No data is copied so this is the most efficient way of accessing.
/// </summary>
public ReadOnlyMemory<T> Memory
{
get { return array.AsMemory(0, count); }
}
/// <summary>
/// Creates a deep clone of this repeated field.
/// </summary>