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] Inline unnecessary helper functions for List #3857

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
17 changes: 7 additions & 10 deletions mojo/stdlib/src/collections/list.mojo
Original file line number Diff line number Diff line change
Expand Up @@ -786,22 +786,23 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False](
Raises:
ValueError: If the value is not found in the list.
"""
var start_normalized = start

var s_len = len(self)
var start_normalized = start
var stop_normalized: Int
if stop is None:
# Default end
stop_normalized = len(self)
stop_normalized = s_len
else:
stop_normalized = stop.value()

if start_normalized < 0:
start_normalized += len(self)
start_normalized += s_len
if stop_normalized < 0:
stop_normalized += len(self)
stop_normalized += s_len

start_normalized = _clip(start_normalized, 0, len(self))
stop_normalized = _clip(stop_normalized, 0, len(self))
start_normalized = max(0, min(start_normalized, s_len))
stop_normalized = max(0, min(stop_normalized, s_len))

for i in range(start_normalized, stop_normalized):
if self[i] == value:
Expand Down Expand Up @@ -1078,7 +1079,3 @@ struct List[T: CollectionElement, hint_trivial_type: Bool = False](
return List[T, hint_trivial_type](
ptr=data, length=size, capacity=capacity
)


fn _clip(value: Int, start: Int, end: Int) -> Int:
return max(start, min(value, end))