Skip to content

Commit 4237e52

Browse files
authored
ensure DirectBuffer.CheckLimit can be inlined (#840)
1 parent 5a602ff commit 4237e52

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

csharp/sbe-dll/DirectBuffer.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public int Capacity
120120
{
121121
get { return _capacity; }
122122
}
123-
123+
124124
/// <summary>
125125
/// Check that a given limit is not greater than the capacity of a buffer from a given offset.
126126
/// </summary>
@@ -129,17 +129,22 @@ public void CheckLimit(int limit)
129129
{
130130
if (limit > _capacity)
131131
{
132-
if (bufferOverflow == null)
133-
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));
132+
TryResizeBuffer(limit);
133+
}
134+
}
134135

135-
var newBuffer = bufferOverflow(_capacity, limit);
136+
private void TryResizeBuffer(int limit)
137+
{
138+
if (bufferOverflow == null)
139+
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));
136140

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

140-
Marshal.Copy((IntPtr)_pBuffer, newBuffer, 0, _capacity);
141-
Wrap(newBuffer);
142-
}
143+
if (newBuffer == null)
144+
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));
145+
146+
Marshal.Copy((IntPtr)_pBuffer, newBuffer, 0, _capacity);
147+
Wrap(newBuffer);
143148
}
144149

145150
/// <summary>

0 commit comments

Comments
 (0)