Skip to content

Commit

Permalink
[External] [stdlib] Use reversed(range(...)) in more places (#39453)
Browse files Browse the repository at this point in the history
[External] [stdlib] Use `reversed(range(...))` in more places

Co-authored-by: soraros <soraros@users.noreply.github.com>
Closes #2473
MODULAR_ORIG_COMMIT_REV_ID: 1f5d1bb1337cc6601c52ca387a2b75179c8c7a20
  • Loading branch information
soraros authored and JoeLoser committed May 8, 2024
1 parent 28d90c1 commit c749952
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions stdlib/src/builtin/builtin_list.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,8 @@ struct VariadicListMem[
# Otherwise this is a variadic of owned elements, destroy them. We
# destroy in backwards order to match how arguments are normally torn
# down when CheckLifetimes is left to its own devices.
for i in range(len(self), 0, -1):
destroy_pointee(UnsafePointer.address_of(self[i - 1]))
for i in reversed(range(len(self))):
destroy_pointee(UnsafePointer.address_of(self[i]))

@always_inline
fn __len__(self) -> Int:
Expand Down
2 changes: 1 addition & 1 deletion stdlib/src/utils/stringref.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ fn _memrmem[
return DTypePointer[type]()
if needle_len == 1:
return _memrchr[type](haystack, needle[0], haystack_len)
for i in range(haystack_len - needle_len, -1, -1):
for i in reversed(range(haystack_len - needle_len + 1)):
if haystack[i] != needle[0]:
continue
if memcmp(haystack + i + 1, needle + 1, needle_len - 1) == 0:
Expand Down

0 comments on commit c749952

Please sign in to comment.