Move #!
checking.
Currently does the "is this a `#!` at the start of the file?" check for every single token(!) This commit moves it so it only happens once.
This commit is contained in:
parent
14281e6147
commit
9640d1c023
1 changed files with 8 additions and 9 deletions
|
@ -38,10 +38,16 @@ pub struct UnmatchedBrace {
|
||||||
|
|
||||||
pub(crate) fn parse_token_trees<'a>(
|
pub(crate) fn parse_token_trees<'a>(
|
||||||
sess: &'a ParseSess,
|
sess: &'a ParseSess,
|
||||||
src: &'a str,
|
mut src: &'a str,
|
||||||
start_pos: BytePos,
|
mut start_pos: BytePos,
|
||||||
override_span: Option<Span>,
|
override_span: Option<Span>,
|
||||||
) -> (PResult<'a, TokenStream>, Vec<UnmatchedBrace>) {
|
) -> (PResult<'a, TokenStream>, Vec<UnmatchedBrace>) {
|
||||||
|
// Skip `#!`, if present.
|
||||||
|
if let Some(shebang_len) = rustc_lexer::strip_shebang(src) {
|
||||||
|
src = &src[shebang_len..];
|
||||||
|
start_pos = start_pos + BytePos::from_usize(shebang_len);
|
||||||
|
}
|
||||||
|
|
||||||
StringReader { sess, start_pos, pos: start_pos, src, override_span }.into_token_trees()
|
StringReader { sess, start_pos, pos: start_pos, src, override_span }.into_token_trees()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,13 +71,6 @@ impl<'a> StringReader<'a> {
|
||||||
fn next_token(&mut self) -> (Spacing, Token) {
|
fn next_token(&mut self) -> (Spacing, Token) {
|
||||||
let mut spacing = Spacing::Joint;
|
let mut spacing = Spacing::Joint;
|
||||||
|
|
||||||
// Skip `#!` at the start of the file
|
|
||||||
if self.pos == self.start_pos
|
|
||||||
&& let Some(shebang_len) = rustc_lexer::strip_shebang(self.src)
|
|
||||||
{
|
|
||||||
self.pos = self.pos + BytePos::from_usize(shebang_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip trivial (whitespace & comments) tokens
|
// Skip trivial (whitespace & comments) tokens
|
||||||
loop {
|
loop {
|
||||||
let start_src_index = self.src_index(self.pos);
|
let start_src_index = self.src_index(self.pos);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue