about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorBrendan Zabarauskas <bjzaba@yahoo.com.au>2014-10-23 04:58:48 +1100
committerBrendan Zabarauskas <bjzaba@yahoo.com.au>2014-10-26 09:53:30 +1100
commit34dacb80cea4071233fb74b479e1f8c148a0be03 (patch)
tree77ad86a151e8757e9f5e4eded7e62488510dfe9f /src/libsyntax
parentdfb4163f8380e9a1aaf64a7474de30634bca4034 (diff)
downloadrust-34dacb80cea4071233fb74b479e1f8c148a0be03.tar.gz
rust-34dacb80cea4071233fb74b479e1f8c148a0be03.zip
Reduce the size of the TokenTree
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs5
-rw-r--r--src/libsyntax/ext/quote.rs3
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs5
-rw-r--r--src/libsyntax/ext/tt/transcribe.rs13
-rw-r--r--src/libsyntax/fold.rs25
-rw-r--r--src/libsyntax/parse/parser.rs2
-rw-r--r--src/libsyntax/print/pprust.rs3
7 files changed, 34 insertions, 22 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index f87c7cf0215..a6156bfa496 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -629,8 +629,7 @@ pub enum TokenTree {
     /// A single token
     TtToken(Span, ::parse::token::Token),
     /// A delimited sequence of token trees
-    // FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST.
-    TtDelimited(Span, Delimiter, Rc<Vec<TokenTree>>, Delimiter),
+    TtDelimited(Span, Rc<(Delimiter, Vec<TokenTree>, Delimiter)>),
 
     // These only make sense for right-hand-sides of MBE macros:
 
@@ -649,7 +648,7 @@ impl TokenTree {
     pub fn get_span(&self) -> Span {
         match *self {
             TtToken(span, _)           => span,
-            TtDelimited(span, _, _, _) => span,
+            TtDelimited(span, _)       => span,
             TtSequence(span, _, _, _)  => span,
             TtNonterminal(span, _)     => span,
         }
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs
index 5c4290d217b..6f1fd90adfa 100644
--- a/src/libsyntax/ext/quote.rs
+++ b/src/libsyntax/ext/quote.rs
@@ -651,7 +651,8 @@ fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> {
                                     vec!(e_tok));
             vec!(cx.stmt_expr(e_push))
         },
-        ast::TtDelimited(sp, ref open, ref tts, ref close) => {
+        ast::TtDelimited(sp, ref delimed) => {
+            let (ref open, ref tts, ref close) = **delimed;
             mk_tt(cx, sp, &open.to_tt()).into_iter()
                 .chain(tts.iter().flat_map(|tt| mk_tt(cx, sp, tt).into_iter()))
                 .chain(mk_tt(cx, sp, &close.to_tt()).into_iter())
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index 75ad2e0fde8..8b45cf34e80 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -172,7 +172,10 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt,
                     MatchedNonterminal(NtTT(ref tt)) => {
                         match **tt {
                             // ignore delimiters
-                            TtDelimited(_, _, ref tts, _) => (**tts).clone(),
+                            TtDelimited(_, ref delimed) => {
+                                let (_, ref tts, _) = **delimed;
+                                tts.clone()
+                            },
                             _ => cx.span_fatal(sp, "macro rhs must be delimited"),
                         }
                     },
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs
index 59b87afe0ee..fde950e4999 100644
--- a/src/libsyntax/ext/tt/transcribe.rs
+++ b/src/libsyntax/ext/tt/transcribe.rs
@@ -128,9 +128,13 @@ impl Add<LockstepIterSize, LockstepIterSize> for LockstepIterSize {
 
 fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize {
     match *t {
-        // The opening and closing delimiters are both tokens, so they are
-        // treated as `LisUnconstrained`.
-        TtDelimited(_, _, ref tts, _) | TtSequence(_, ref tts, _, _) => {
+        TtDelimited(_, ref delimed) => {
+            let (_, ref tts, _) = **delimed;
+            tts.iter().fold(LisUnconstrained, |size, tt| {
+                size + lockstep_iter_size(tt, r)
+            })
+        },
+        TtSequence(_, ref tts, _, _) => {
             tts.iter().fold(LisUnconstrained, |size, tt| {
                 size + lockstep_iter_size(tt, r)
             })
@@ -202,7 +206,8 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan {
             (*frame.forest)[frame.idx].clone()
         };
         match t {
-            TtDelimited(_, open, tts, close) => {
+            TtDelimited(_, ref delimed) => {
+                let (ref open, ref tts, ref close) = **delimed;
                 let mut forest = Vec::with_capacity(1 + tts.len() + 1);
                 forest.push(open.to_tt());
                 forest.extend(tts.iter().map(|x| (*x).clone()));
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 2dfa69b1f38..0f9ab5c6b26 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -571,17 +571,20 @@ pub fn noop_fold_tt<T: Folder>(tt: &TokenTree, fld: &mut T) -> TokenTree {
     match *tt {
         TtToken(span, ref tok) =>
             TtToken(span, fld.fold_token(tok.clone())),
-        TtDelimited(span, ref open, ref tts, ref close) =>
-            TtDelimited(span,
-                        Delimiter {
-                            span: open.span,
-                            token: fld.fold_token(open.token.clone())
-                        },
-                        Rc::new(fld.fold_tts(tts.as_slice())),
-                        Delimiter {
-                            span: close.span,
-                            token: fld.fold_token(close.token.clone())
-                        }),
+        TtDelimited(span, ref delimed) => {
+            let (ref open, ref tts, ref close) = **delimed;
+            TtDelimited(span, Rc::new((
+                            Delimiter {
+                                span: open.span,
+                                token: fld.fold_token(open.token.clone())
+                            },
+                            fld.fold_tts(tts.as_slice()),
+                            Delimiter {
+                                span: close.span,
+                                token: fld.fold_token(close.token.clone())
+                            },
+                        )))
+        },
         TtSequence(span, ref pattern, ref sep, is_optional) =>
             TtSequence(span,
                        Rc::new(fld.fold_tts(pattern.as_slice())),
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index ebca362b9d8..f8fa053b7ae 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2615,7 +2615,7 @@ impl<'a> Parser<'a> {
                 // Expand to cover the entire delimited token tree
                 let span = Span { hi: self.span.hi, ..pre_span };
 
-                TtDelimited(span, open, Rc::new(tts), close)
+                TtDelimited(span, Rc::new((open, tts, close)))
             }
             _ => parse_non_delim_tt_tok(self)
         }
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index e3b7a164108..97c177b696c 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1020,7 +1020,8 @@ impl<'a> State<'a> {
     /// expression arguments as expressions). It can be done! I think.
     pub fn print_tt(&mut self, tt: &ast::TokenTree) -> IoResult<()> {
         match *tt {
-            ast::TtDelimited(_, ref open, ref tts, ref close) => {
+            ast::TtDelimited(_, ref delimed) => {
+                let (ref open, ref tts, ref close) = **delimed;
                 try!(word(&mut self.s, parse::token::to_string(&open.token).as_slice()));
                 try!(space(&mut self.s));
                 try!(self.print_tts(tts.as_slice()));