mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-04 14:01:12 +00:00
[C#] Improve Span<> utilization (#8588)
There are a couple instances where the ByteBuffer's Span property was accessed in a loop. + Extracted the use of the property outside of the loop to save a few cpu cycles. Access to the allocator's internal buffer isn't exposed as a ReadOnlySpan<byte> from the ByteBuffer or the FlatBufferBuilder. + Added a few convenience functions to access the buffer using a ReadOnlySpan<byte>. There are a few cases where built in Span extensions can be used to run optimized code. + Added the use of Span.Fill() and ReadOnlySpan.SequenceCompareTo to replace existing loops. Co-authored-by: Björn Harrtell <bjornharrtell@users.noreply.github.com> Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
@@ -957,6 +957,21 @@ namespace Google.FlatBuffers
|
||||
return _bb.ToSizedArray();
|
||||
}
|
||||
|
||||
#if ENABLE_SPAN_T && UNSAFE_BYTEBUFFER
|
||||
/// <summary>
|
||||
/// A utility function return the ByteBuffer data as a
|
||||
/// `ReadOnlySpan<byte>`.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A `ReadOnlySpan<byte>` that references the internal
|
||||
/// ByteBuffer data.
|
||||
/// </returns>
|
||||
public ReadOnlySpan<byte> SizedReadOnlySpan()
|
||||
{
|
||||
return _bb.ToSizedReadOnlySpan();
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Finalize a buffer, pointing to the given `rootTable`.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user