Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e35507a

Browse files
pakrymahsonkhan
authored andcommitted
Add ReadOnlySequence API (#26694)
* Add ReadOnlyBuffer API * Add tests * Copyrights * PR Comments * Fix test * Add ToString test, remove extra members * Move more methods to extension class * Revert ref changes * Test changes * Set 1 of PR comments * Set 2 of PR comments * Set 2 of PR comments * Another set of style changes * Add tests, remove ToString * More tests * Add OM ctor back * PR Comments and coverege * More comments * Fix tests * Add owned memory back * ReadOnlySequence * Tests * Add array
1 parent 7af4af9 commit e35507a

16 files changed

+1654
-36
lines changed

src/System.Memory/ref/System.Memory.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ public ref partial struct Enumerator
161161
public bool MoveNext() { throw null; }
162162
}
163163
}
164+
public readonly partial struct SequencePosition : System.IEquatable<System.SequencePosition>
165+
{
166+
private readonly object _dummy;
167+
public SequencePosition(object segment, int index) { throw null; }
168+
public int Index { get { throw null; } }
169+
public object Segment { get { throw null; } }
170+
[System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)(1))]
171+
public override bool Equals(object obj) { throw null; }
172+
public bool Equals(System.SequencePosition position) { throw null; }
173+
public override int GetHashCode() { throw null; }
174+
public static bool operator ==(System.SequencePosition left, System.SequencePosition right) { throw null; }
175+
public static bool operator !=(System.SequencePosition left, System.SequencePosition right) { throw null; }
176+
public override string ToString() { throw null; }
177+
}
164178
public readonly ref partial struct Span<T>
165179
{
166180
private readonly object _dummy;
@@ -202,6 +216,12 @@ public ref partial struct Enumerator
202216
}
203217
namespace System.Buffers
204218
{
219+
public partial interface IMemoryList<T>
220+
{
221+
System.Memory<T> Memory { get; }
222+
System.Buffers.IMemoryList<T> Next { get; }
223+
long RunningIndex { get; }
224+
}
205225
public partial interface IRetainable
206226
{
207227
bool Release();
@@ -248,6 +268,49 @@ public void Dispose() { }
248268
public abstract void Retain();
249269
protected internal abstract bool TryGetArray(out System.ArraySegment<T> arraySegment);
250270
}
271+
public static partial class BuffersExtensions
272+
{
273+
public static void CopyTo<T>(this System.Buffers.ReadOnlySequence<T> sequence, System.Span<T> destination) { }
274+
public static System.Nullable<System.SequencePosition> PositionOf<T>(this System.Buffers.ReadOnlySequence<T> sequence, T value) where T : System.IEquatable<T> { throw null; }
275+
public static T[] ToArray<T>(this System.Buffers.ReadOnlySequence<T> sequence) { throw null; }
276+
}
277+
public readonly partial struct ReadOnlySequence<T>
278+
{
279+
private readonly object _dummy;
280+
public static readonly System.Buffers.ReadOnlySequence<T> Empty;
281+
public ReadOnlySequence(System.Buffers.IMemoryList<T> startSegment, int startIndex, System.Buffers.IMemoryList<T> endSegment, int endIndex) { throw null; }
282+
public ReadOnlySequence(T[] array) { throw null; }
283+
public ReadOnlySequence(T[] array, int start, int length) { throw null; }
284+
public ReadOnlySequence(System.ReadOnlyMemory<T> memory) { throw null; }
285+
public ReadOnlySequence(System.Buffers.OwnedMemory<T> memory) { throw null; }
286+
public ReadOnlySequence(System.Buffers.OwnedMemory<T> memory, int start, int length) { throw null; }
287+
public System.SequencePosition End { get { throw null; } }
288+
public System.ReadOnlyMemory<T> First { get { throw null; } }
289+
public bool IsEmpty { get { throw null; } }
290+
public bool IsSingleSegment { get { throw null; } }
291+
public long Length { get { throw null; } }
292+
public System.SequencePosition Start { get { throw null; } }
293+
public System.Buffers.ReadOnlySequence<T>.Enumerator GetEnumerator() { throw null; }
294+
public System.SequencePosition GetPosition(System.SequencePosition origin, long offset) { throw null; }
295+
public System.Buffers.ReadOnlySequence<T> Slice(int start, int length) { throw null; }
296+
public System.Buffers.ReadOnlySequence<T> Slice(int start, System.SequencePosition end) { throw null; }
297+
public System.Buffers.ReadOnlySequence<T> Slice(long start) { throw null; }
298+
public System.Buffers.ReadOnlySequence<T> Slice(long start, long length) { throw null; }
299+
public System.Buffers.ReadOnlySequence<T> Slice(long start, System.SequencePosition end) { throw null; }
300+
public System.Buffers.ReadOnlySequence<T> Slice(System.SequencePosition start) { throw null; }
301+
public System.Buffers.ReadOnlySequence<T> Slice(System.SequencePosition start, int length) { throw null; }
302+
public System.Buffers.ReadOnlySequence<T> Slice(System.SequencePosition start, long length) { throw null; }
303+
public System.Buffers.ReadOnlySequence<T> Slice(System.SequencePosition start, System.SequencePosition end) { throw null; }
304+
public override string ToString() { throw null; }
305+
public bool TryGet(ref System.SequencePosition position, out System.ReadOnlyMemory<T> data, bool advance = true) { throw null; }
306+
public partial struct Enumerator
307+
{
308+
private object _dummy;
309+
public Enumerator(System.Buffers.ReadOnlySequence<T> sequence) { throw null; }
310+
public System.ReadOnlyMemory<T> Current { get { throw null; } }
311+
public bool MoveNext() { throw null; }
312+
}
313+
}
251314
public readonly partial struct StandardFormat : System.IEquatable<System.Buffers.StandardFormat>
252315
{
253316
private readonly int _dummy;

src/System.Memory/src/Resources/Strings.resx

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<root>
3-
<!--
4-
Microsoft ResX Schema
5-
3+
<!--
4+
Microsoft ResX Schema
5+
66
Version 2.0
7-
8-
The primary goals of this format is to allow a simple XML format
9-
that is mostly human readable. The generation and parsing of the
10-
various data types are done through the TypeConverter classes
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
1111
associated with the data types.
12-
12+
1313
Example:
14-
14+
1515
... ado.net/XML headers & schema ...
1616
<resheader name="resmimetype">text/microsoft-resx</resheader>
1717
<resheader name="version">2.0</resheader>
@@ -26,36 +26,36 @@
2626
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
2727
<comment>This is a comment</comment>
2828
</data>
29-
30-
There are any number of "resheader" rows that contain simple
29+
30+
There are any number of "resheader" rows that contain simple
3131
name/value pairs.
32-
33-
Each data row contains a name, and value. The row also contains a
34-
type or mimetype. Type corresponds to a .NET class that support
35-
text/value conversion through the TypeConverter architecture.
36-
Classes that don't support this are serialized and stored with the
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
3737
mimetype set.
38-
39-
The mimetype is used for serialized objects, and tells the
40-
ResXResourceReader how to depersist the object. This is currently not
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
4141
extensible. For a given mimetype the value must be set accordingly:
42-
43-
Note - application/x-microsoft.net.object.binary.base64 is the format
44-
that the ResXResourceWriter will generate, however the reader can
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
4545
read any of the formats listed below.
46-
46+
4747
mimetype: application/x-microsoft.net.object.binary.base64
48-
value : The object must be serialized with
48+
value : The object must be serialized with
4949
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5050
: and then encoded with base64 encoding.
51-
51+
5252
mimetype: application/x-microsoft.net.object.soap.base64
53-
value : The object must be serialized with
53+
value : The object must be serialized with
5454
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
5555
: and then encoded with base64 encoding.
5656
5757
mimetype: application/x-microsoft.net.object.bytearray.base64
58-
value : The object must be serialized into a byte array
58+
value : The object must be serialized into a byte array
5959
: using a System.ComponentModel.TypeConverter
6060
: and then encoded with base64 encoding.
6161
-->
@@ -150,4 +150,10 @@
150150
<data name="Argument_OverlapAlignmentMismatch" xml:space="preserve">
151151
<value>Overlapping spans have mismatching alignment.</value>
152152
</data>
153-
</root>
153+
<data name="EndPositionNotReached" xml:space="preserve">
154+
<value>End position was not reached during enumeration.</value>
155+
</data>
156+
<data name="UnexpectedSegmentType" xml:space="preserve">
157+
<value>Unexpected segment type.</value>
158+
</data>
159+
</root>

src/System.Memory/src/System.Memory.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@
2222
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Release|AnyCPU'" />
2323
<ItemGroup>
2424
<Compile Include="System\MemoryExtensions.cs" />
25+
<Compile Include="System\SequencePosition.cs" />
2526
<Compile Include="System\SpanHelpers.BinarySearch.cs" />
2627
<Compile Include="System\SpanHelpers.T.cs" />
2728
<Compile Include="System\SpanHelpers.byte.cs" />
2829
<Compile Include="System\ThrowHelper.cs" />
2930
<Compile Include="System\Buffers\ArrayMemoryPool.cs" />
3031
<Compile Include="System\Buffers\ArrayMemoryPool.ArrayMemoryPoolBuffer.cs" />
32+
<Compile Include="System\Buffers\SequenceExtensions.cs" />
33+
<Compile Include="System\Buffers\IMemoryList.cs" />
3134
<Compile Include="System\Buffers\MemoryPool.cs" />
3235
<Compile Include="System\Buffers\OperationStatus.cs" />
36+
<Compile Include="System\Buffers\ReadOnlySequence.cs" />
37+
<Compile Include="System\Buffers\ReadOnlySequence_helpers.cs" />
3338
<Compile Include="System\Buffers\Binary\Reader.cs" />
3439
<Compile Include="System\Buffers\Binary\ReaderBigEndian.cs" />
3540
<Compile Include="System\Buffers\Binary\ReaderLittleEndian.cs" />
@@ -123,6 +128,9 @@
123128
</ItemGroup>
124129
<ItemGroup>
125130
<!-- Common or Common-branched source files -->
131+
<Compile Include="$(CommonPath)\System\Numerics\Hashing\HashHelpers.cs">
132+
<Link>Common\System\Collections\HashHelpers.cs</Link>
133+
</Compile>
126134
<Compile Include="$(CommonPath)\System\NotImplemented.cs">
127135
<Link>Common\System\NotImplemented.cs</Link>
128136
</Compile>
@@ -149,4 +157,4 @@
149157
<ProjectReference Include="..\..\System.Numerics.Vectors\src\System.Numerics.Vectors.csproj" />
150158
</ItemGroup>
151159
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
152-
</Project>
160+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace System.Buffers
6+
{
7+
/// <summary>
8+
/// Represents a linked list of <see cref="Memory{T}"/> nodes.
9+
/// </summary>
10+
public interface IMemoryList<T>
11+
{
12+
/// <summary>
13+
/// The <see cref="Memory{T}"/> value for current node.
14+
/// </summary>
15+
Memory<T> Memory { get; }
16+
17+
/// <summary>
18+
/// The next node.
19+
/// </summary>
20+
IMemoryList<T> Next { get; }
21+
22+
/// <summary>
23+
/// The sum of node length before current.
24+
/// </summary>
25+
long RunningIndex { get; }
26+
}
27+
}

0 commit comments

Comments
 (0)