@@ -28,58 +28,68 @@ internal static class Util
2828 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
2929 internal static int ReadInt32 ( BorrowedReference ob , int offset )
3030 {
31+ Debug . Assert ( offset >= 0 ) ;
3132 return Marshal . ReadInt32 ( ob . DangerousGetAddress ( ) , offset ) ;
3233 }
3334 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
3435 internal static long ReadInt64 ( BorrowedReference ob , int offset )
3536 {
37+ Debug . Assert ( offset >= 0 ) ;
3638 return Marshal . ReadInt64 ( ob . DangerousGetAddress ( ) , offset ) ;
3739 }
3840
3941 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4042 internal unsafe static T * ReadPtr < T > ( BorrowedReference ob , int offset )
4143 where T : unmanaged
4244 {
45+ Debug . Assert ( offset >= 0 ) ;
4346 IntPtr ptr = Marshal . ReadIntPtr ( ob . DangerousGetAddress ( ) , offset ) ;
4447 return ( T * ) ptr ;
4548 }
4649
4750 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
4851 internal unsafe static IntPtr ReadIntPtr ( BorrowedReference ob , int offset )
4952 {
53+ Debug . Assert ( offset >= 0 ) ;
5054 return Marshal . ReadIntPtr ( ob . DangerousGetAddress ( ) , offset ) ;
5155 }
5256
5357 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5458 internal unsafe static BorrowedReference ReadRef ( BorrowedReference @ref , int offset )
5559 {
60+ Debug . Assert ( offset >= 0 ) ;
5661 return new BorrowedReference ( ReadIntPtr ( @ref , offset ) ) ;
5762 }
5863
5964 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
6065 internal static void WriteInt32 ( BorrowedReference ob , int offset , int value )
6166 {
67+ Debug . Assert ( offset >= 0 ) ;
6268 Marshal . WriteInt32 ( ob . DangerousGetAddress ( ) , offset , value ) ;
6369 }
6470 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
6571 internal static void WriteInt64 ( BorrowedReference ob , int offset , long value )
6672 {
73+ Debug . Assert ( offset >= 0 ) ;
6774 Marshal . WriteInt64 ( ob . DangerousGetAddress ( ) , offset , value ) ;
6875 }
6976 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
7077 internal unsafe static void WriteIntPtr ( BorrowedReference ob , int offset , IntPtr value )
7178 {
79+ Debug . Assert ( offset >= 0 ) ;
7280 Marshal . WriteIntPtr ( ob . DangerousGetAddress ( ) , offset , value ) ;
7381 }
7482 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
7583 internal unsafe static void WriteRef ( BorrowedReference ob , int offset , in StolenReference @ref )
7684 {
85+ Debug . Assert ( offset >= 0 ) ;
7786 Marshal . WriteIntPtr ( ob . DangerousGetAddress ( ) , offset , @ref . DangerousGetAddress ( ) ) ;
7887 }
7988
8089 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
8190 internal unsafe static void WriteNullableRef ( BorrowedReference ob , int offset , in StolenReference @ref )
8291 {
92+ Debug . Assert ( offset >= 0 ) ;
8393 Marshal . WriteIntPtr ( ob . DangerousGetAddress ( ) , offset , @ref . DangerousGetAddressOrNull ( ) ) ;
8494 }
8595
0 commit comments