Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stdlib] Use out param for __next__() in more iterators #3952

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stdlib/src/collections/deque.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,14 @@ struct _DequeIter[
fn __iter__(self) -> Self:
return self

fn __next__(mut self) -> Pointer[ElementType, deque_lifetime]:
fn __next__(mut self, out p: Pointer[ElementType, deque_lifetime]):
@parameter
if forward:
p = Pointer.address_of(self.src[][self.index])
self.index += 1
return Pointer.address_of(self.src[][self.index - 1])
else:
self.index -= 1
return Pointer.address_of(self.src[][self.index])
p = Pointer.address_of(self.src[][self.index])

fn __len__(self) -> Int:
@parameter
Expand Down
8 changes: 3 additions & 5 deletions stdlib/src/collections/inline_list.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ struct _InlineListIter[
fn __iter__(self) -> Self:
return self

fn __next__(
mut self,
) -> Pointer[T, __origin_of(self.src[][0])]:
fn __next__(mut self, out p: Pointer[T, __origin_of(self.src[][0])]):
@parameter
if forward:
p = Pointer.address_of(self.src[][self.index])
self.index += 1
return Pointer.address_of(self.src[][self.index - 1])
else:
self.index -= 1
return Pointer.address_of(self.src[][self.index])
p = Pointer.address_of(self.src[][self.index])

@always_inline
fn __has_next__(self) -> Bool:
Expand Down
8 changes: 3 additions & 5 deletions stdlib/src/memory/span.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,14 @@ struct _SpanIter[
return self

@always_inline
fn __next__(
mut self,
) -> Pointer[T, origin]:
fn __next__(mut self, out p: Pointer[T, origin]):
@parameter
if forward:
p = Pointer.address_of(self.src[self.index])
self.index += 1
return Pointer.address_of(self.src[self.index - 1])
else:
self.index -= 1
return Pointer.address_of(self.src[self.index])
p = Pointer.address_of(self.src[self.index])

@always_inline
fn __has_next__(self) -> Bool:
Expand Down
Loading