Fast byte-level blit, fill, match, and uninit allocation for MoonBit
moon add bikallem/blit// Copy between FixedArray[Byte] buffers (safe for overlapping regions)
@blit.blit_fixed_array(dst, dst_offset, src, src_offset, length)
// Copy from Bytes into FixedArray[Byte]
@blit.blit_bytes(dst, dst_offset, src, src_offset, length)
// Copy from BytesView into FixedArray[Byte]
@blit.blit_bytesview(dst, dst_offset, src, src_offset, length)// Fill a region with a single byte value
@blit.fill_bytes(dst, dst_offset, value, length)// Count matching bytes between two FixedArray[Byte] regions
@blit.match_length(a, a_offset, b, b_offset, max_len)
// Count matching bytes between two Bytes regions
@blit.match_length_bytes(a, a_offset, b, b_offset, max_len)
// Count matching bytes within a BytesView
@blit.match_length_bv(src, a, b, max_len)let buf = @blit.Buffer::new(size_hint=1024)
// Write
buf.write_byte(b'a')
buf.write_bytes(b"hello")
buf.write_bytesview(some_bytes[1:4])
buf.write_fixed(fixed_arr, offset, len)
// Unchecked write (caller must ensure capacity)
buf.ensure_capacity(10)
buf.write_byte_unchecked(b'x')
// Read
buf.get_byte(0) // bounds-check free read
buf.length() // current byte count
buf.data() // backing FixedArray[Byte]
// Internal copy (handles overlapping regions)
buf.copy_from_self(src_pos, len)
// Finalize: make_uninit(pos) + blit + unsafe_reinterpret_as_bytes
let bytes = buf.to_bytes()
// Reuse allocated memory
buf.reset()@blit.make_uninit(len) // -> FixedArray[Byte]
@blit.make_uninit_int(len) // -> FixedArray[Int]
@blit.make_uninit_uint(len) // -> FixedArray[UInt]type Bufferfn blit_bytes(dst : FixedArray[Byte], dst_offset : Int, src : Bytes, src_offset : Int, length : Int) -> Unitfn blit_bytesview(dst : FixedArray[Byte], dst_offset : Int, src : BytesView, src_offset : Int, length : Int) -> Unitfn blit_fixed_array(dst : FixedArray[Byte], dst_offset : Int, src : FixedArray[Byte], src_offset : Int, length : Int) -> Unitfn fill_bytes(dst : FixedArray[Byte], dst_offset : Int, value : Byte, length : Int) -> Unitfn make_uninit(len : Int) -> FixedArray[Byte]fn match_length(a : FixedArray[Byte], a_offset : Int, b : FixedArray[Byte], b_offset : Int, max_len : Int) -> Intfn match_length_bv(src : BytesView, a : Int, b : Int, max_len : Int) -> Intfn match_length_bytes(a : Bytes, a_offset : Int, b : Bytes, b_offset : Int, max_len : Int) -> Intfn shift_int_array(arr : FixedArray[Int], len : Int, delta : Int, floor : Int) -> UnitFast byte-level blit, fill, match, and uninit allocation for MoonBit