Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate Bytes::blit #1572

Merged
merged 2 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builtin/builtin.mbti
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion builtin/bytes.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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] })
}

///|
Expand Down
38 changes: 1 addition & 37 deletions builtin/bytes_block.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 0 additions & 21 deletions builtin/panic_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading