Skip to content

chore: avoid recompute length in std.slice #1241

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -206,27 +206,27 @@ limitations under the License.
local invar =
// loop invariant with defaults applied
{
length: std.length(indexable),
indexable: indexable,
index:
if index == null
then 0
else
if index < 0
then std.max(0, std.length(indexable) + index)
then std.max(0, self.length + index)
else index,
end:
if end == null
then std.length(indexable)
then self.length
else
if end < 0
then std.length(indexable) + end
then self.length + end
else end,
step:
if step == null
then 1
else step,
length: std.length(indexable),
type: std.type(indexable),
type: std.type(indexable)
};
assert invar.step >= 0 : 'got [%s:%s:%s] but negative steps are not supported' % [invar.index, invar.end, invar.step];
assert step != 0 : 'got %s but step must be greater than 0' % step;
Expand Down