Skip to content

Commit

Permalink
Optimize Array.iter and Array.iter_mut a bit
Browse files Browse the repository at this point in the history
Similar to ByteArray.iter, we don't need to perform bounds checking in
these methods.

Changelog: performance
  • Loading branch information
yorickpeterse committed Oct 24, 2023
1 parent 07632a3 commit e3886ae
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions std/src/std/array.inko
Expand Up @@ -364,7 +364,11 @@ class builtin Array[T] {
let max = @size

Stream.new fn move {
if idx < max { Option.Some(get(idx := idx + 1)) } else { Option.None }
if idx < max {
Option.Some(get_unchecked(idx := idx + 1))
} else {
Option.None
}
}
}

Expand Down Expand Up @@ -627,7 +631,11 @@ impl Array if T: mut {
let max = @size

Stream.new fn move {
if idx < max { Option.Some(get_mut(idx := idx + 1)) } else { Option.None }
if idx < max {
Option.Some(get_unchecked_mut(idx := idx + 1))
} else {
Option.None
}
}
}

Expand Down

0 comments on commit e3886ae

Please sign in to comment.