Blit
Range copy over the sequence types a real primitive can back.
One blit factored across the sequence-like types, instead of a separate copy routine per type. blit(src, src_off, len, dst, dst_off) returns a destination whose len elements starting at dst_off are the len elements of src starting at src_off, with the rest of dst unchanged. As with memcpy, the ranges [src_off, src_off + len) and [dst_off, dst_off + len) are expected to lie within the two sequences.
Instanced only where a real primitive backs the copy: String over the substring slice primitive, Array over the in-place array_get and array_set primitives, and Bytes over the byte buffer’s in-place buf_set, so a uniquely owned array or buffer destination is overwritten without a fresh allocation. Plain lists stay uninstanced on purpose: a cons list has no random access or bulk copy, so a blit would be a structural walk that rebuilds the prefix rather than a copy.
Type Classes
Blit
class Blit(s)
blit : (s, Int, Int, s, Int) -> s
Overwrite dst[dst_off .. dst_off + len) with src[src_off .. src_off + len) and return the updated destination.
Instances
blitString
instance blitString : Blit(String)
Splice the source range over the destination range with the string slice primitive: the untouched prefix and suffix of dst are sliced out and rejoined around the copied middle.
blitArray
instance blitArray : Blit(Array(a))
Overwrite dst[dst_off + i] with src[src_off + i] for each i in 0 .. len via array_set, which writes in place when dst is uniquely owned and copies otherwise, so the observable result never depends on ownership.
blitBytes
instance blitBytes : Blit(Bytes)
Overwrite dst[dst_off + i] with src[src_off + i] for each i in 0 .. len via the buffer’s buf_set, which writes in place when the destination buffer is uniquely owned and copies otherwise, so the observable result never depends on ownership.