Skip to content

Commit

Permalink
[External] [stdlib] Use out param for __next__() in more iterators (#…
Browse files Browse the repository at this point in the history
…54072)

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

Apply the change from #3941 to
other iterators where it applies.

Co-authored-by: bgreni <[email protected]>
Closes #3952
MODULAR_ORIG_COMMIT_REV_ID: 9d96b4c3da86b8a5f4e990a6029dddc8fc7bc84d
  • Loading branch information
bgreni authored and modularbot committed Jan 17, 2025
1 parent 7269824 commit 168cde9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
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

0 comments on commit 168cde9

Please sign in to comment.