Skip to content

Conversation

@floitsch
Copy link
Member

@floitsch floitsch commented Nov 7, 2025

No description provided.

@floitsch floitsch requested a review from kasperl November 7, 2025 13:57
@cla-bot cla-bot bot added the cla-signed The contributors have signed the CLA label Nov 7, 2025
Copy link
Member

@kasperl kasperl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

// performance, we can reimplement with the a more traditional
// implementation.
first_ := 0
last_ := 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It is a little bit weird that first is inclusive and last isn't, just from a naming perspective. Maybe start/end would be nicer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

result = backing.remove-last
else:
result = backing[last - 1]
last_ = last - 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably null out the removed element in the backing store, like it is done for remove-first.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch.
done.

Returns the value that was removed.
*/
remove --at/int -> any:
last := size - 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a different last than last_.

if at >= last >> 1:
return backing_.remove --at=(first_ + at)
if not 0 <= at <= last: throw "OUT_OF_BOUNDS"
if at >= (last >> 1):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. And refactored it to make it easier to follow.

last := last_
reserved := backing.size - last
sz := last - first
if first * 2 > last:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here? Why do we multiply here and shift in the other place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switched to shift for consistency.
done.

backing.resize size
last := last_
reserved := backing.size - last
sz := last - first
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we compute this eagerly? Why isn't this called size?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow this file started to copy fields into locals (probably for efficiency reasons), and I have continued that "tradition".
It can't be called "size", as that would shadow the method, which isn't allowed.

expect-equals "[1, 42]" d.stringify
expect-equals "[103, 3]" d2.stringify


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop one newline?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The contributors have signed the CLA

Development

Successfully merging this pull request may close these issues.

3 participants