@@ -63,9 +63,10 @@ public short this[int idx]
6363
6464 public static Block8x8 Load ( Span < short > data )
6565 {
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 ) ;
6970 }
7071
7172 /// <summary>
@@ -93,9 +94,10 @@ public short[] ToArray()
9394 /// </summary>
9495 public void CopyTo ( Span < short > destination )
9596 {
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 ) ;
99101 }
100102
101103 /// <summary>
@@ -124,19 +126,6 @@ public void LoadFrom(ReadOnlySpan<byte> source)
124126 }
125127 }
126128
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-
140129 /// <summary>
141130 /// Cast and copy <see cref="Size"/> <see cref="int"/>-s from the beginning of 'source' span.
142131 /// </summary>
0 commit comments