@@ -221,23 +221,24 @@ public static Span<byte> GetBytes<T>(T[] items, bool marshalElements, Span<byte>
221221 if ( sizeOfItem < MaxStackLimit )
222222 {
223223 Span < byte > currentItem = stackalloc byte [ sizeOfItem ] ;
224- GetBytesInternal ( currentItem , resultSpan ) ;
224+ GetBytesInternal ( items , sizeOfItem , marshalElements , currentItem , resultSpan ) ;
225225 }
226226 else
227227 {
228228 Span < byte > currentItem = new byte [ sizeOfItem ] ;
229- GetBytesInternal ( currentItem , resultSpan ) ;
229+ GetBytesInternal ( items , sizeOfItem , marshalElements , currentItem , resultSpan ) ;
230230 }
231231
232232 return resultSpan ;
233233
234- void GetBytesInternal ( Span < byte > currentItem , Span < byte > span )
234+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
235+ void GetBytesInternal ( T [ ] items , int sizeOfItem , bool marshalElements , Span < byte > currentItem , Span < byte > resultSpan )
235236 {
236237 for ( int x = 0 ; x < items . Length ; x ++ )
237238 {
238239 Struct . GetBytes ( ref items [ x ] , marshalElements , currentItem ) ;
239- currentItem . CopyTo ( span ) ;
240- span = span . Slice ( sizeOfItem ) ;
240+ currentItem . CopyTo ( resultSpan ) ;
241+ resultSpan = resultSpan . Slice ( sizeOfItem ) ;
241242 }
242243 }
243244 }
@@ -268,17 +269,18 @@ public static Span<byte> GetBytes<T>(T[] items, Span<byte> buffer) where T : unm
268269 if ( sizeof ( T ) < MaxStackLimit )
269270 {
270271 Span < byte > currentItem = stackalloc byte [ sizeof ( T ) ] ;
271- GetBytesInternal ( currentItem , resultSpan ) ;
272+ GetBytesInternal ( items , currentItem , resultSpan ) ;
272273 }
273274 else
274275 {
275276 Span < byte > currentItem = new byte [ sizeof ( T ) ] ;
276- GetBytesInternal ( currentItem , resultSpan ) ;
277+ GetBytesInternal ( items , currentItem , resultSpan ) ;
277278 }
278279
279280 return resultSpan ;
280281
281- void GetBytesInternal ( Span < byte > currentItem , Span < byte > span )
282+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
283+ void GetBytesInternal ( T [ ] items , Span < byte > currentItem , Span < byte > span )
282284 {
283285 for ( int x = 0 ; x < items . Length ; x ++ )
284286 {
0 commit comments