@@ -63,9 +63,10 @@ public short this[int idx]
63
63
64
64
public static Block8x8 Load ( Span < short > data )
65
65
{
66
- Unsafe . SkipInit ( out Block8x8 result ) ;
67
- result . LoadFrom ( data ) ;
68
- return result ;
66
+ DebugGuard . MustBeGreaterThanOrEqualTo ( data . Length , Size , "data is too small" ) ;
67
+
68
+ ref byte src = ref Unsafe . As < short , byte > ( ref MemoryMarshal . GetReference ( data ) ) ;
69
+ return Unsafe . ReadUnaligned < Block8x8 > ( ref src ) ;
69
70
}
70
71
71
72
/// <summary>
@@ -93,9 +94,10 @@ public short[] ToArray()
93
94
/// </summary>
94
95
public void CopyTo ( Span < short > destination )
95
96
{
96
- ref byte selfRef = ref Unsafe . As < Block8x8 , byte > ( ref this ) ;
97
- ref byte destRef = ref MemoryMarshal . GetReference ( MemoryMarshal . Cast < short , byte > ( destination ) ) ;
98
- Unsafe . CopyBlockUnaligned ( ref destRef , ref selfRef , Size * sizeof ( short ) ) ;
97
+ DebugGuard . MustBeGreaterThanOrEqualTo ( destination . Length , Size , "destination is too small" ) ;
98
+
99
+ ref byte destRef = ref Unsafe . As < short , byte > ( ref MemoryMarshal . GetReference ( destination ) ) ;
100
+ Unsafe . WriteUnaligned ( ref destRef , this ) ;
99
101
}
100
102
101
103
/// <summary>
@@ -124,19 +126,6 @@ public void LoadFrom(ReadOnlySpan<byte> source)
124
126
}
125
127
}
126
128
127
- /// <summary>
128
- /// Load raw 16bit integers from source.
129
- /// </summary>
130
- /// <param name="source">Source</param>
131
- [ MethodImpl ( InliningOptions . ShortMethod ) ]
132
- public void LoadFrom ( Span < short > source )
133
- {
134
- ref byte sourceRef = ref Unsafe . As < short , byte > ( ref MemoryMarshal . GetReference ( source ) ) ;
135
- ref byte destRef = ref Unsafe . As < Block8x8 , byte > ( ref this ) ;
136
-
137
- Unsafe . CopyBlockUnaligned ( ref destRef , ref sourceRef , Size * sizeof ( short ) ) ;
138
- }
139
-
140
129
/// <summary>
141
130
/// Cast and copy <see cref="Size"/> <see cref="int"/>-s from the beginning of 'source' span.
142
131
/// </summary>
0 commit comments