]> git.lizzy.rs Git - rust.git/commitdiff
Slash the ast::Stmt type from 104 to 24 bytes.
authorHuon Wilson <dbau.pp+github@gmail.com>
Fri, 5 Dec 2014 09:10:22 +0000 (01:10 -0800)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 29 Dec 2014 12:55:25 +0000 (23:55 +1100)
(on platforms with 64-bit pointers.)

The StmtMac variant is rather large and also fairly rare, so let's
optimise the common case.

src/libsyntax/ast.rs
src/libsyntax/ext/expand.rs
src/libsyntax/fold.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs
src/libsyntax/visit.rs

index 0c8c17b080bf33f9a0914d40b2d8e3832506daaa..d4932fbb5f1c545f85b9e7becba26f2cd3fc0dd2 100644 (file)
@@ -607,7 +607,7 @@ pub enum Stmt_ {
     /// Expr with trailing semi-colon (may have any type):
     StmtSemi(P<Expr>, NodeId),
 
-    StmtMac(Mac, MacStmtStyle),
+    StmtMac(P<Mac>, MacStmtStyle),
 }
 
 #[deriving(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)]
index f2b6f6bfe16b05e7e46d74e7d48854866c894cda..d2d624fa05e77be015f21786649b3295cda4def5 100644 (file)
@@ -672,7 +672,7 @@ fn expand_stmt(s: Stmt, fld: &mut MacroExpander) -> SmallVector<P<Stmt>> {
         StmtMac(mac, style) => (mac, style),
         _ => return expand_non_macro_stmt(s, fld)
     };
-    let expanded_stmt = match expand_mac_invoc(mac, s.span,
+    let expanded_stmt = match expand_mac_invoc(mac.and_then(|m| m), s.span,
                                                 |r| r.make_stmt(),
                                                 mark_stmt, fld) {
         Some(stmt) => stmt,
index 0803de1bb53e215bc76ef6420f07e47a221f7130..c58901701f530068df47429b8dabdf65baa0174f 100644 (file)
@@ -1461,7 +1461,7 @@ pub fn noop_fold_stmt<T: Folder>(Spanned {node, span}: Stmt, folder: &mut T)
             }))
         }
         StmtMac(mac, semi) => SmallVector::one(P(Spanned {
-            node: StmtMac(folder.fold_mac(mac), semi),
+            node: StmtMac(mac.map(|m| folder.fold_mac(m)), semi),
             span: span
         }))
     }
index 94b61ba56d2e5b938d3012f8f6991ae2a8c4dbf6..15b92b2edbf98038d2a2020af83ad7b3fe524476 100644 (file)
@@ -3940,7 +3940,7 @@ fn parse_block_tail_(&mut self, lo: BytePos, s: BlockCheckMode,
                                     expr = Some(
                                         self.mk_mac_expr(span.lo,
                                                          span.hi,
-                                                         m.node));
+                                                         m.and_then(|x| x.node)));
                                 }
                                 _ => {
                                     stmts.push(P(Spanned {
index 3d53bd8aadf70a0270cf4057b54e3cfaa492d69a..623f20bccd2ee36a100797e3b7bd19228c9f7479 100644 (file)
@@ -1337,7 +1337,7 @@ pub fn print_stmt(&mut self, st: &ast::Stmt) -> IoResult<()> {
                     ast::MacStmtWithBraces => token::Brace,
                     _ => token::Paren
                 };
-                try!(self.print_mac(mac, delim));
+                try!(self.print_mac(&**mac, delim));
                 match style {
                     ast::MacStmtWithBraces => {}
                     _ => try!(word(&mut self.s, ";")),
index 4cc93467a7cc21f6044c7c83017874f7e05f570a..714339d0f0aaa84b8c33656b0a3176cc93a9ac54 100644 (file)
@@ -730,7 +730,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) {
         StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => {
             visitor.visit_expr(&**expression)
         }
-        StmtMac(ref macro, _) => visitor.visit_mac(macro),
+        StmtMac(ref macro, _) => visitor.visit_mac(&**macro),
     }
 }