Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9dadb3e

Browse files
committedFeb 20, 2025·
Make std.iter.Stream an inline type
Since this type just wraps a closure there's no need to heap allocate it. Changelog: performance
1 parent 40389bb commit 9dadb3e

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed
 

‎std/src/std/iter.inko

+3-3
Original file line numberDiff line numberDiff line change
@@ -679,17 +679,17 @@ trait pub IntoIter[T] {
679679
# nums.next # => Option.Some(1)
680680
# }
681681
# ```
682-
type pub Stream[T] {
682+
type pub inline Stream[T] {
683683
let @func: fn -> Option[T]
684684

685685
# Returns a new iterator using the closure.
686-
fn pub static new(func: fn -> Option[T]) -> Stream[T] {
686+
fn pub inline static new(func: fn -> Option[T]) -> Stream[T] {
687687
Stream(func)
688688
}
689689
}
690690

691691
impl Iter[T] for Stream {
692-
fn pub mut next -> Option[T] {
692+
fn pub inline mut next -> Option[T] {
693693
@func.call
694694
}
695695
}

‎std/src/std/range.inko

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import std.clone (Clone)
2424
import std.cmp (Contains, Equal)
2525
import std.fmt (Format, Formatter)
2626
import std.hash (Hash, Hasher)
27-
import std.iter (Iter, Stream)
27+
import std.iter (Stream)
2828

2929
# A range of integers.
3030
trait pub Range: Contains[Int] + Hash + Format {
@@ -41,10 +41,10 @@ trait pub Range: Contains[Int] + Hash + Format {
4141
fn pub size -> Int
4242

4343
# Returns an iterator over the values in `self`.
44-
fn pub iter -> Iter[Int]
44+
fn pub iter -> Stream[Int]
4545

4646
# Moves `self` into an iterator.
47-
fn pub move into_iter -> Iter[Int] {
47+
fn pub move into_iter -> Stream[Int] {
4848
iter
4949
}
5050
}

‎std/src/std/string.inko

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ trait pub Bytes {
172172
fn pub byte(index: Int) -> Int
173173

174174
# Returns an iterator over the bytes in `self`.
175-
fn pub bytes -> Iter[Int]
175+
fn pub bytes -> Stream[Int]
176176

177177
# Returns the number of bytes in `self`.
178178
fn pub size -> Int

0 commit comments

Comments
 (0)
Please sign in to comment.