Closed
Description
It seems like the dedup_by
implementation makes two passes over the data, making many more copies than are strictly necessary. Doing this allows the same_bucket
implementation to panic without causing a leak. I wouldn't call this bad, but it was a surprise to see that it was doing the extra work.
Mimicking the way Drain
handles this and temporarily shortening the vector allows us to cut down on the copies (and also conveniently removes a panicking branch).
I wonder if it makes sense to document the trade-off that std
makes here? Imo, it'd make it easier to use the library correctly in the way that https://doc.rust-lang.org/std/vec/struct.Vec.html#current-implementation-7 does.