diff --git a/builtin/builtin.mbti b/builtin/builtin.mbti index 8010054e4..6ead74d8b 100644 --- a/builtin/builtin.mbti +++ b/builtin/builtin.mbti @@ -718,7 +718,7 @@ impl FixedArray { } impl Bytes { - blit(Bytes, Int, Bytes, Int, Int) -> Unit + blit(Bytes, Int, Bytes, Int, Int) -> Unit //deprecated copy(Bytes) -> Bytes length(Bytes) -> Int make(Int, Byte) -> Bytes diff --git a/builtin/bytes.mbt b/builtin/bytes.mbt index fd7d45cd7..a8149574d 100644 --- a/builtin/bytes.mbt +++ b/builtin/bytes.mbt @@ -240,7 +240,7 @@ pub fn FixedArray::blit_from_bytes( /// } /// ``` pub fn Bytes::copy(self : Bytes) -> Bytes { - Bytes::new(self.length())..blit(0, self, 0, self.length()) + Bytes::makei(self.length(), fn(i) { self[i] }) } ///| diff --git a/builtin/bytes_block.mbt b/builtin/bytes_block.mbt index 108c82480..c3293f55a 100644 --- a/builtin/bytes_block.mbt +++ b/builtin/bytes_block.mbt @@ -24,43 +24,7 @@ fn Bytes::unsafe_blit( ///| /// Copies a sequence of bytes from a source byte sequence to a destination byte /// sequence. -/// -/// Parameters: -/// -/// * `self` : The destination byte sequence where bytes will be copied to. -/// * `dst_offset` : The starting position in the destination sequence where -/// bytes will be written. -/// * `src` : The source byte sequence from which bytes will be copied. -/// * `src_offset` : The starting position in the source sequence from which -/// bytes will be read. -/// * `length` : The number of bytes to copy. -/// -/// Throws a runtime error if: -/// -/// * `length` is negative -/// * `dst_offset` is negative -/// * `src_offset` is negative -/// * The range `[dst_offset, dst_offset + length)` exceeds the length of the -/// destination sequence -/// * The range `[src_offset, src_offset + length)` exceeds the length of the -/// source sequence -/// -/// Example: -/// -/// ```moonbit -/// test "Bytes::blit" { -/// let dst = Bytes::of_string("Hello, world!") -/// let src = Bytes::of_string("MOONBIT") -/// dst.blit(14, src, 0, 8) -/// @json.inspect!(dst.to_unchecked_string(), content="Hello, MOONd!") -/// } -/// -/// test "panic Bytes::blit/out_of_bounds" { -/// let dst = Bytes::of_string("Hello") -/// let src = Bytes::of_string("World") -/// ignore(dst.blit(6, src, 0, 20)) // Range exceeds destination length -/// } -/// ``` +/// @alert deprecated "Bytes is about to be changed to immutable, use `FixedArray[Byte]` instead" pub fn Bytes::blit( self : Bytes, dst_offset : Int, diff --git a/builtin/panic_test.mbt b/builtin/panic_test.mbt index bd062add4..4d7dd05b0 100644 --- a/builtin/panic_test.mbt +++ b/builtin/panic_test.mbt @@ -197,27 +197,6 @@ test "panic from_octets coverage for empty octets" { BigInt::from_octets(b"") |> ignore } -test "panic blit_negative_length" { - let b1 = Bytes::of_string("abcdef") - let b2 = Bytes::of_string("ABCDEF") - // Attempt to blit with a negative length - b1.blit(2, b2, 3, -1) -} - -test "panic blit_out_of_bounds_src" { - let b1 = Bytes::of_string("abcdef") - let b2 = Bytes::of_string("ABCDEF") - // Attempt to blit with src_offset + length exceeding src length - b1.blit(4, b2, 10, 4) -} - -test "panic blit_out_of_bounds_dst" { - let b1 = Bytes::of_string("abcdef") - let b2 = Bytes::of_string("ABCDEF") - // Attempt to blit with dst_offset + length exceeding dst length - b1.blit(8, b2, 6, 6) -} - test "panic sub_string with invalid byte_length" { let bytes = Bytes::of_string("Hello, World!") bytes.to_unchecked_string(offset=0, length=-1) |> ignore