Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C#] Make DirectBuffer.CheckLimit inlinable #840

Merged
merged 3 commits into from
Mar 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions csharp/sbe-dll/DirectBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public int Capacity
{
get { return _capacity; }
}

/// <summary>
/// Check that a given limit is not greater than the capacity of a buffer from a given offset.
/// </summary>
Expand All @@ -129,17 +129,22 @@ public void CheckLimit(int limit)
{
if (limit > _capacity)
{
if (bufferOverflow == null)
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));
TryResizeBuffer(limit);
}
}

var newBuffer = bufferOverflow(_capacity, limit);
private void TryResizeBuffer(int limit)
{
if (bufferOverflow == null)
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));

if (newBuffer == null)
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));
var newBuffer = bufferOverflow(_capacity, limit);

Marshal.Copy((IntPtr)_pBuffer, newBuffer, 0, _capacity);
Wrap(newBuffer);
}
if (newBuffer == null)
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));

Marshal.Copy((IntPtr)_pBuffer, newBuffer, 0, _capacity);
Wrap(newBuffer);
}

/// <summary>
Expand Down