about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-01-03 03:49:01 +0000
committerbors <bors@rust-lang.org>2022-01-03 03:49:01 +0000
commitb5da80871d5e22401e03ce5ed73200ece8bdc7a6 (patch)
tree9b97e7463597eab896f2db39b9c39413b97aa6a1 /compiler/rustc_data_structures/src
parent8f3238f898163f09726c3d2b2cc9bafb09da26f3 (diff)
parent3d8d3f14356c0bc4d8759dfd59aa4b2b4a104dc1 (diff)
downloadrust-b5da80871d5e22401e03ce5ed73200ece8bdc7a6.tar.gz
rust-b5da80871d5e22401e03ce5ed73200ece8bdc7a6.zip
Auto merge of #92395 - Kobzol:rustdoc-bindings-thin-vec, r=camelid
Rustdoc: use ThinVec for GenericArgs bindings

The bindings are almost always empty. This reduces the size of `PathSegment` and `GenericArgs` by about one fourth.
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/thin_vec.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_data_structures/src/thin_vec.rs b/compiler/rustc_data_structures/src/thin_vec.rs
index b5d2d24736c..716259142d1 100644
--- a/compiler/rustc_data_structures/src/thin_vec.rs
+++ b/compiler/rustc_data_structures/src/thin_vec.rs
@@ -5,7 +5,7 @@ use std::iter::FromIterator;
 /// A vector type optimized for cases where this size is usually 0 (cf. `SmallVec`).
 /// The `Option<Box<..>>` wrapping allows us to represent a zero sized vector with `None`,
 /// which uses only a single (null) pointer.
-#[derive(Clone, Encodable, Decodable, Debug)]
+#[derive(Clone, Encodable, Decodable, Debug, Hash, Eq, PartialEq)]
 pub struct ThinVec<T>(Option<Box<Vec<T>>>);
 
 impl<T> ThinVec<T> {
@@ -20,6 +20,13 @@ impl<T> ThinVec<T> {
     pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> {
         self.into_iter()
     }
+
+    pub fn push(&mut self, item: T) {
+        match *self {
+            ThinVec(Some(ref mut vec)) => vec.push(item),
+            ThinVec(None) => *self = vec![item].into(),
+        }
+    }
 }
 
 impl<T> From<Vec<T>> for ThinVec<T> {
@@ -101,10 +108,7 @@ impl<T> Extend<T> for ThinVec<T> {
     }
 
     fn extend_one(&mut self, item: T) {
-        match *self {
-            ThinVec(Some(ref mut vec)) => vec.push(item),
-            ThinVec(None) => *self = vec![item].into(),
-        }
+        self.push(item)
     }
 
     fn extend_reserve(&mut self, additional: usize) {