diff options
| author | Camelid <camelidcamel@gmail.com> | 2021-01-09 12:35:47 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-09 12:35:47 -0800 |
| commit | befd1530984489781bc0b7283f82898734928ff2 (patch) | |
| tree | 17f023ad90b814369c8287c6910a725eb35d67a5 /library/alloc/src/vec/mod.rs | |
| parent | c8915eebeaaef9f7cc1cff6ffd97f578b03c2ac9 (diff) | |
| download | rust-befd1530984489781bc0b7283f82898734928ff2.tar.gz rust-befd1530984489781bc0b7283f82898734928ff2.zip | |
Add comment to `Vec::truncate` explaining `>` vs `>=`
Hopefully this will prevent people from continuing to ask about this over and over again :) See [this Zulip discussion][1] for more. [1]: https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Vec.3A.3Atruncate.20implementation
Diffstat (limited to 'library/alloc/src/vec/mod.rs')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 2a83eb33fe3..1ca194c3361 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -990,6 +990,9 @@ impl<T, A: Allocator> Vec<T, A> { // such that no value will be dropped twice in case `drop_in_place` // were to panic once (if it panics twice, the program aborts). unsafe { + // Note: It's intentional that this is `>` and not `>=`. + // Changing it to `>=` has negative performance + // implications in some cases. See #78884 for more. if len > self.len { return; } |
