Skip to content

Commit d09e512

Browse files
committed
Remove a loop in ext::tt::transcribe.
1 parent be76056 commit d09e512

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,43 +151,34 @@ fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize {
151151
/// EFFECT: advances the reader's token field
152152
fn tt_next_token(r: &mut TtReader, prev_span: Span) -> Option<TokenTree> {
153153
loop {
154-
let should_pop = if let Some(frame) = r.stack.last() {
155-
if frame.idx < frame.forest.len() {
156-
break;
157-
}
158-
!frame.dotdotdoted || *r.repeat_idx.last().unwrap() == *r.repeat_len.last().unwrap() - 1
159-
} else {
160-
return None;
154+
let frame = match r.stack.last() {
155+
Some(frame) => frame.clone(),
156+
None => return None,
161157
};
162158

163-
/* done with this set; pop or repeat? */
164-
if should_pop {
165-
let prev = r.stack.pop().unwrap();
166-
if let Some(frame) = r.stack.last_mut() {
167-
frame.idx += 1;
159+
if frame.idx == frame.forest.len() {
160+
if frame.dotdotdoted &&
161+
*r.repeat_idx.last().unwrap() == *r.repeat_len.last().unwrap() - 1 {
162+
*r.repeat_idx.last_mut().unwrap() += 1;
163+
r.stack.last_mut().unwrap().idx = 0;
164+
if let Some(tk) = r.stack.last().unwrap().sep.clone() {
165+
return Some(TokenTree::Token(prev_span, tk)); // repeat same span, I guess
166+
}
168167
} else {
169-
return None;
170-
}
171-
if prev.dotdotdoted {
172-
r.repeat_idx.pop();
173-
r.repeat_len.pop();
174-
}
175-
} else { /* repeat */
176-
*r.repeat_idx.last_mut().unwrap() += 1;
177-
r.stack.last_mut().unwrap().idx = 0;
178-
if let Some(tk) = r.stack.last().unwrap().sep.clone() {
179-
return Some(TokenTree::Token(prev_span, tk)); // repeat same span, I guess
168+
r.stack.pop();
169+
match r.stack.last_mut() {
170+
Some(frame) => frame.idx += 1,
171+
None => return None,
172+
}
173+
if frame.dotdotdoted {
174+
r.repeat_idx.pop();
175+
r.repeat_len.pop();
176+
}
180177
}
178+
continue
181179
}
182-
}
183-
loop { /* because it's easiest, this handles `TokenTree::Delimited` not starting
184-
with a `TokenTree::Token`, even though it won't happen */
185-
let t = {
186-
let frame = r.stack.last().unwrap();
187-
// FIXME(pcwalton): Bad copy.
188-
frame.forest.get_tt(frame.idx)
189-
};
190-
match t {
180+
181+
match frame.forest.get_tt(frame.idx) {
191182
TokenTree::Sequence(sp, seq) => {
192183
// FIXME(pcwalton): Bad copy.
193184
match lockstep_iter_size(&TokenTree::Sequence(sp, seq.clone()),

0 commit comments

Comments
 (0)