rust-lang / hashbrown

Rust port of Google's SwissTable hash map
https://rust-lang.github.io/hashbrown
Apache License 2.0
2.42k stars 283 forks source link

Remove unnecessary `add` in `clone_from_impl` #519

Open JustForFun88 opened 6 months ago

JustForFun88 commented 6 months ago

The guard.0 = index + 1 in the implementation of clone_from _impl is completely unnecessary, since an invalid index can be set in advance.

Amanieu commented 6 months ago

The + 1 is implicitly calculated by the iterator anyways, so it doesn't cost anything extra in optimized builds.

I prefer the original form of the code since guard.0 clearly indicates the point that separates the initialized part of the array vs the uninitialized part. This also avoids the need to special-case usize::MAX.