Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BuffersExtensions.cs
Go to the documentation of this file.
2
3namespace System.Buffers;
4
5public static class BuffersExtensions
6{
7 [MethodImpl(MethodImplOptions.AggressiveInlining)]
9 {
10 if (source.IsSingleSegment)
11 {
12 int num = source.First.Span.IndexOf(value);
13 if (num != -1)
14 {
15 return source.Seek(num);
16 }
17 return null;
18 }
19 return PositionOfMultiSegment(in source, value);
20 }
21
23 {
24 SequencePosition position = source.Start;
25 SequencePosition origin = position;
26 ReadOnlyMemory<T> memory;
27 while (source.TryGet(ref position, out memory))
28 {
29 int num = memory.Span.IndexOf(value);
30 if (num != -1)
31 {
32 return source.GetPosition(num, origin);
33 }
34 if (position.GetObject() == null)
35 {
36 break;
37 }
38 origin = position;
39 }
40 return null;
41 }
42
43 [MethodImpl(MethodImplOptions.AggressiveInlining)]
45 {
46 if (source.IsSingleSegment)
47 {
48 ReadOnlySpan<T> span = source.First.Span;
49 if (span.Length > destination.Length)
50 {
51 System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.destination);
52 }
53 span.CopyTo(destination);
54 }
55 else
56 {
57 CopyToMultiSegment(in source, destination);
58 }
59 }
60
62 {
63 if (sequence.Length > destination.Length)
64 {
65 System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.destination);
66 }
67 SequencePosition position = sequence.Start;
68 ReadOnlyMemory<T> memory;
69 while (sequence.TryGet(ref position, out memory))
70 {
71 ReadOnlySpan<T> span = memory.Span;
72 span.CopyTo(destination);
73 if (position.GetObject() != null)
74 {
75 destination = destination.Slice(span.Length);
76 continue;
77 }
78 break;
79 }
80 }
81
82 public static T[] ToArray<T>(this in ReadOnlySequence<T> sequence)
83 {
84 T[] array = new T[sequence.Length];
85 CopyTo(in sequence, array);
86 return array;
87 }
88
89 [MethodImpl(MethodImplOptions.AggressiveInlining)]
91 {
92 Span<T> span = writer.GetSpan();
93 if (value.Length <= span.Length)
94 {
95 value.CopyTo(span);
96 writer.Advance(value.Length);
97 }
98 else
99 {
101 }
102 }
103
105 {
106 ReadOnlySpan<T> readOnlySpan = source;
107 while (true)
108 {
109 int num = Math.Min(destination.Length, readOnlySpan.Length);
110 readOnlySpan.Slice(0, num).CopyTo(destination);
111 writer.Advance(num);
112 readOnlySpan = readOnlySpan.Slice(num);
113 if (readOnlySpan.Length > 0)
114 {
115 destination = writer.GetSpan();
116 if (destination.IsEmpty)
117 {
119 }
120 continue;
121 }
122 break;
123 }
124 }
125}
static ? SequencePosition PositionOfMultiSegment< T >(in ReadOnlySequence< T > source, T value)
static void WriteMultiSegment< T >(IBufferWriter< T > writer, in ReadOnlySpan< T > source, Span< T > destination)
static void CopyToMultiSegment< T >(in ReadOnlySequence< T > sequence, Span< T > destination)
static void Write< T >(this IBufferWriter< T > writer, ReadOnlySpan< T > value)
static void CopyTo< T >(this in ReadOnlySequence< T > source, Span< T > destination)
static ? SequencePosition PositionOf< T >(this in ReadOnlySequence< T > source, T value)
static T[] ToArray< T >(this in ReadOnlySequence< T > sequence)
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
unsafe ReadOnlySpan< T > Span
void CopyTo(Span< T > destination)
ReadOnlySpan< T > Slice(int start)
void CopyTo(Span< T > destination)
Definition Span.cs:224
int Length
Definition Span.cs:70