Add Advance APIs to builder and writer types

このコミットが含まれているのは:
Sergio Pedri committed 2023-09-30 01:34:04 +02:00
1 親 8daf482eb8
コミット 117bdc2ab3
2ファイル変更
+46

検索条件に一致するファイルはありません

+26
ファイルの表示
@@ -60,6 +60,20 @@ internal struct ImmutableArrayBuilder<T> : IDisposable
get => this.writer!.WrittenSpan.Length;
}
/// <summary>
/// Advances the current writer and gets a <see cref="Span{T}"/> to the requested memory area.
/// </summary>
/// <param name="requestedSize">The requested size to advance by.</param>
/// <returns>A <see cref="Span{T}"/> to the requested memory area.</returns>
/// <remarks>
/// No other data should be written to the builder while the returned <see cref="Span{T}"/>
/// is in use, as it could invalidate the memory area wrapped by it, if resizing occurs.
/// </remarks>
public readonly Span<T> Advance(int requestedSize)
{
return this.writer!.Advance(requestedSize);
}
/// <inheritdoc cref="ImmutableArray{T}.Builder.Add(T)"/>
public readonly void Add(T item)
{
@@ -159,6 +173,18 @@ internal struct ImmutableArrayBuilder<T> : IDisposable
get => new(this.array, 0, this.index);
}
/// <inheritdoc cref="ImmutableArrayBuilder{T}.Advance"/>
public Span<T> Advance(int requestedSize)
{
EnsureCapacity(requestedSize);
Span<T> span = this.array.AsSpan(this.index, requestedSize);
this.index += requestedSize;
return span;
}
/// <inheritdoc cref="ImmutableArrayBuilder{T}.Add"/>
public void Add(T value)
{
+20
ファイルの表示
@@ -72,6 +72,26 @@ internal sealed class IndentedTextWriter : IDisposable
}
}
/// <summary>
/// Advances the current writer and gets a <see cref="Span{T}"/> to the requested memory area.
/// </summary>
/// <param name="requestedSize">The requested size to advance by.</param>
/// <returns>A <see cref="Span{T}"/> to the requested memory area.</returns>
/// <remarks>
/// No other data should be written to the writer while the returned <see cref="Span{T}"/>
/// is in use, as it could invalidate the memory area wrapped by it, if resizing occurs.
/// </remarks>
public Span<char> Advance(int requestedSize)
{
// Add the leading whitespace if needed (same as WriteRawText below)
if (this.builder.Count == 0 || this.builder.WrittenSpan[^1] == DefaultNewLine)
{
this.builder.AddRange(this.currentIndentation.AsSpan());
}
return this.builder.Advance(requestedSize);
}
/// <summary>
/// Increases the current indentation level.
/// </summary>