]> git.lizzy.rs Git - rust.git/commitdiff
Add `Body::shrink_to_fit`
authorJonas Schievink <jonasschievink@gmail.com>
Sun, 4 Apr 2021 01:26:16 +0000 (03:26 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Sun, 4 Apr 2021 01:26:16 +0000 (03:26 +0200)
crates/hir_def/src/body.rs

index ad3d5afbec76f7581c430b9cd788ac148a3c69f0..a5fc652a75339767c4b420965b27fe3f00c14238 100644 (file)
@@ -302,7 +302,8 @@ pub(crate) fn body_with_source_map_query(
             }
         };
         let expander = Expander::new(db, file_id, module);
-        let (body, source_map) = Body::new(db, expander, params, body);
+        let (mut body, source_map) = Body::new(db, expander, params, body);
+        body.shrink_to_fit();
         (Arc::new(body), Arc::new(source_map))
     }
 
@@ -328,6 +329,15 @@ fn new(
     ) -> (Body, BodySourceMap) {
         lower::lower(db, expander, params, body)
     }
+
+    fn shrink_to_fit(&mut self) {
+        let Self { _c: _, body_expr: _, block_scopes, exprs, labels, params, pats } = self;
+        block_scopes.shrink_to_fit();
+        exprs.shrink_to_fit();
+        labels.shrink_to_fit();
+        params.shrink_to_fit();
+        pats.shrink_to_fit();
+    }
 }
 
 impl Index<ExprId> for Body {