Skip to content

Commit

Permalink
optimize Array append method by using blit_to for improved efficiency
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Dec 3, 2024
1 parent 3f1c7a5 commit 180fedd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions builtin/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,13 @@ pub fn op_add[T](self : Array[T], other : Array[T]) -> Array[T] {
/// let v2 = [6, 7, 8]
/// v1.append(v2)
/// ```
/// TODO: could be made more efficient doing direct mem.copy
pub fn append[T](self : Array[T], other : Array[T]) -> Unit {
self.reserve_capacity(self.length() + other.length())
for v in other {
self.push(v)
}
other.blit_to(
self,
len=other.length(),
src_offset=0,
dst_offset=self.length(),
)
}

///|
Expand Down

0 comments on commit 180fedd

Please sign in to comment.