Skip to content

Conversation

@kjeremy
Copy link
Contributor

@kjeremy kjeremy commented Mar 30, 2020

I find this more readable and it flattens out the body a little. Others may disagree.

I find this more readable and it flattens out the body a little.
Copy link
Member

@lnicola lnicola left a comment

Choose a reason for hiding this comment

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

I wonder if we need the reserve call above.

@kjeremy
Copy link
Contributor Author

kjeremy commented Mar 30, 2020

I was wondering that myself. I'm not sure if extend does the reserve in once step. resize is another option but that could truncate.

@lnicola
Copy link
Member

lnicola commented Mar 30, 2020

I think it can thanks to the size hint, but I'm not sure.

@kjeremy
Copy link
Contributor Author

kjeremy commented Mar 30, 2020

Ok I think it is. Take implements TrustedLen so the specializated gets used by SpecExtend.

`Take` implements `TrustedLen` so we are guaranteed that only one
reserve call will be made.
@kjeremy
Copy link
Contributor Author

kjeremy commented Mar 30, 2020

I'm not sure what that failing macos test is about.

@lnicola
Copy link
Member

lnicola commented Mar 30, 2020

I think it's a race, it happened in another PR or two today.

}

let fill = (idx + 1).saturating_sub(self.v.len());
self.v.extend(std::iter::repeat_with(|| None).take(fill));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.v.extend(std::iter::repeat_with(|| None).take(fill));
self.v.resize(idx + 1, None);

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the imperative rain on your functional parade :)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, wait, it indeed can truncate, I guess that needs to be (idx + 1).max(self.v.len())

@matklad
Copy link
Contributor

matklad commented Mar 31, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Mar 31, 2020

@bors bors bot merged commit 30466e0 into rust-lang:master Mar 31, 2020
@kjeremy kjeremy deleted the simplify-arena-map branch March 31, 2020 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants