@@ -55,8 +55,8 @@ impl PpAnn for NoAnn {}
55
55
56
56
pub struct Comments < ' a > {
57
57
sm : & ' a SourceMap ,
58
- comments : Vec < Comment > ,
59
- current : usize ,
58
+ // Stored in reverse order so we can consume them by popping.
59
+ reversed_comments : Vec < Comment > ,
60
60
}
61
61
62
62
/// Returns `None` if the first `col` chars of `s` contain a non-whitespace char.
@@ -182,19 +182,17 @@ fn gather_comments(sm: &SourceMap, path: FileName, src: String) -> Vec<Comment>
182
182
183
183
impl < ' a > Comments < ' a > {
184
184
pub fn new ( sm : & ' a SourceMap , filename : FileName , input : String ) -> Comments < ' a > {
185
- let comments = gather_comments ( sm, filename, input) ;
186
- Comments { sm, comments, current : 0 }
185
+ let mut comments = gather_comments ( sm, filename, input) ;
186
+ comments. reverse ( ) ;
187
+ Comments { sm, reversed_comments : comments }
187
188
}
188
189
189
190
fn peek ( & self ) -> Option < & Comment > {
190
- self . comments . get ( self . current )
191
+ self . reversed_comments . last ( )
191
192
}
192
193
193
- // FIXME: This shouldn't probably clone lmao
194
194
fn next ( & mut self ) -> Option < Comment > {
195
- let cmnt = self . comments . get ( self . current ) . cloned ( ) ;
196
- self . current += 1 ;
197
- cmnt
195
+ self . reversed_comments . pop ( )
198
196
}
199
197
200
198
fn trailing_comment (
0 commit comments