File tree Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Expand file tree Collapse file tree 2 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -361,9 +361,7 @@ fn panic_expand(
361
361
} ;
362
362
363
363
// FIXME(slow): quote! have a way to expand to builder to make this a vec!
364
- let mut mutable_trees = std:: mem:: take ( & mut call. token_trees ) . into_vec ( ) ;
365
- mutable_trees. push ( tt:: TokenTree :: Subtree ( subtree) ) ;
366
- call. token_trees = mutable_trees. into_boxed_slice ( ) ;
364
+ call. push ( tt:: TokenTree :: Subtree ( subtree) ) ;
367
365
368
366
ExpandResult :: ok ( call)
369
367
}
@@ -395,9 +393,7 @@ fn unreachable_expand(
395
393
} ;
396
394
397
395
// FIXME(slow): quote! have a way to expand to builder to make this a vec!
398
- let mut mutable_trees = std:: mem:: take ( & mut call. token_trees ) . into_vec ( ) ;
399
- mutable_trees. push ( tt:: TokenTree :: Subtree ( subtree) ) ;
400
- call. token_trees = mutable_trees. into_boxed_slice ( ) ;
396
+ call. push ( tt:: TokenTree :: Subtree ( subtree) ) ;
401
397
402
398
ExpandResult :: ok ( call)
403
399
}
Original file line number Diff line number Diff line change @@ -77,6 +77,17 @@ impl<S: Span> Subtree<S> {
77
77
Subtree { delimiter : Delimiter :: invisible_delim_spanned ( span) , token_trees : Box :: new ( [ ] ) }
78
78
}
79
79
80
+ /// This is slow, and should be avoided, as it will always reallocate!
81
+ pub fn push ( & mut self , subtree : TokenTree < S > ) {
82
+ let mut mutable_trees = std:: mem:: take ( & mut self . token_trees ) . into_vec ( ) ;
83
+
84
+ // Reserve exactly space for one element, to avoid `into_boxed_slice` having to reallocate again.
85
+ mutable_trees. reserve_exact ( 1 ) ;
86
+ mutable_trees. push ( subtree) ;
87
+
88
+ self . token_trees = mutable_trees. into_boxed_slice ( ) ;
89
+ }
90
+
80
91
pub fn visit_ids ( & mut self , f : & mut impl FnMut ( S ) -> S ) {
81
92
self . delimiter . open = f ( self . delimiter . open ) ;
82
93
self . delimiter . close = f ( self . delimiter . close ) ;
You can’t perform that action at this time.
0 commit comments