Skip to content

Commit a28c543

Browse files
peter-jerry-yebobzhang
authored andcommitted
refactor: adjust fixed-array to bytes conversion
1 parent 1d9d172 commit a28c543

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

bytes/bytes.mbt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ pub fn Bytes::from_fixedarray(arr : FixedArray[Byte], len? : Int) -> Bytes {
7474
None => arr.length()
7575
Some(x) => x
7676
}
77-
Bytes::makei(len, i => arr[i])
77+
let result = FixedArray::make(len, Byte::default())
78+
arr.blit_to(result, len~)
79+
result.unsafe_reinterpret_as_bytes()
7880
}
7981
8082
///|
@@ -171,15 +173,17 @@ pub fn from_iter(iter : Iter[Byte]) -> Bytes {
171173
/// ),
172174
/// )
173175
/// ```
174-
/// TODO: marked as intrinsic, inline if it is constant
175176
pub fn Bytes::of(arr : FixedArray[Byte]) -> Bytes {
176-
Bytes::makei(arr.length(), i => arr[i])
177+
let len = arr.length()
178+
let result = FixedArray::make(len, Byte::default())
179+
arr.blit_to(result, len~)
180+
result.unsafe_reinterpret_as_bytes()
177181
}
178182
179183
///|
180184
/// same as `Bytes::of`
181185
pub fn of(arr : FixedArray[Byte]) -> Bytes {
182-
Bytes::makei(arr.length(), i => arr[i])
186+
Bytes::of(arr)
183187
}
184188
185189
///|

0 commit comments

Comments
 (0)