about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2021-01-10 16:56:07 +0900
committerGitHub <noreply@github.com>2021-01-10 16:56:07 +0900
commit19b8c65e4e0af841a9ecaa99b5e1ae3c73ff9c7f (patch)
treed54626e59f9c48ea6652c768971496cd3e43dded
parent3e735c6e933d82c52ab7202617fc8d009e696956 (diff)
parentbefd1530984489781bc0b7283f82898734928ff2 (diff)
downloadrust-19b8c65e4e0af841a9ecaa99b5e1ae3c73ff9c7f.tar.gz
rust-19b8c65e4e0af841a9ecaa99b5e1ae3c73ff9c7f.zip
Rollup merge of #80857 - camelid:vec-truncate-comment, r=scottmcm
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

r? ``@scottmcm``
-rw-r--r--library/alloc/src/vec/mod.rs3
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;
             }