File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff 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>
You can’t perform that action at this time.
0 commit comments