Skip to content

Commit

Permalink
ensure DirectBuffer.CheckLimit can be inlined (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
szehetner authored Mar 31, 2021
1 parent 5a602ff commit 4237e52
Showing 1 changed file with 14 additions and 9 deletions.
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

0 comments on commit 4237e52

Please sign in to comment.