-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Implement append and split_off for VecMap (RFC 509) #22494
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
Implement append and split_off for VecMap (RFC 509) #22494
Conversation
/// assert_eq!(b[4], "d"); | ||
/// ``` | ||
pub fn split_off(&mut self, at: usize) -> Self { | ||
assert!(at <= self.len(), "`at` out of bounds"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For Sorted Maps, at
shouldn't have any assert, I reckon. It's basically a predecessor query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is, the backing storage is an implementation detail for Maps, unlike sequences.
I'm not sure exactly how much VecMap should try to help out with foot-guns. In particular should it assume that inputs are reasonable and that VecMaps are small and dense? Or should it make a best effort not to do something catastrophic when the VecMap has a lot of empty space (particularly at the tail). CC @huonw |
|
||
if at == 0 { | ||
// Move all elements to other | ||
other.append(self); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems inefficient. Why not just mem::swap(self, other)?
r=me with the last two changes and squashed commits. 😄 |
55f0e06
to
87e1bbb
Compare
I've addressed both comments and squashed the commits. I think, we're ready to go 🎉 . |
By the way, shouldn't I also include a |
87e1bbb
to
5d8d879
Compare
Oh, whoops, yes! I am still getting used to the new stability stuff. |
3ee0028
to
0b2029d
Compare
I've added them now. BTW: Is there a convention when to use |
Ugh #[inline] is basically cargo culting in the standard libraries IMHO. It does two things: It hints to LLVM that inlining is more desriable than usual, and it makes the function a candidate for cross-crate-inling (by including the source in the compiled crate). The first one is very dubious, because LLVM's defaults should be smarter than us in this regard. The second one is completely inapplicable for almost all collections code because generic code is already available for cross-crate inlining (since you need the source for monomorphization). It's a battle I simply don't have the energy to fight. Everyone does it. It'd be great if you excluded them IMO, but I can't fight the world on this. |
0b2029d
to
ec7145e
Compare
Alright, I've removed them. I always thought that the compiler should know better what to inline. Didn't know about the cross-crate-inlining, though. |
@bors r+ ec7145e Great work! |
⌛ Testing commit ec7145e with merge 81cec05... |
💔 Test failed - auto-mac-64-opt |
|
Whoops, needs a |
Implements `append()` and `split_off()` for `VecMap`. It's worth noting that `append()` will overwrite existing keys (the RFC doesn't specify how `append()` should handle duplicate keys). cc rust-lang#19986
ec7145e
to
25d3e01
Compare
Oops! Fixed |
Implements
append()
andsplit_off()
forVecMap
. It's worth noting thatappend()
will overwrite existing keys (the RFC doesn't specify howappend()
should handle duplicate keys).cc #19986
r? @gankro