diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-04-06 12:08:39 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-04-07 12:51:50 +1000 |
| commit | d9592c2d9f0db851b090c10c0cc3560b87fc7789 (patch) | |
| tree | d2c6f22ebb2cc5e244b5c15609622c363146efdd /compiler/rustc_parse | |
| parent | c2afaba465e0bf44b9b37beba8d908b78dcdadc7 (diff) | |
| download | rust-d9592c2d9f0db851b090c10c0cc3560b87fc7789.tar.gz rust-d9592c2d9f0db851b090c10c0cc3560b87fc7789.zip | |
Shrink `Nonterminal`.
By heap allocating the argument within `NtPath`, `NtVis`, and `NtStmt`. This slightly reduces cumulative and peak allocation amounts, most notably on `deep-vector`.
Diffstat (limited to 'compiler/rustc_parse')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/path.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 4 |
5 files changed, 8 insertions, 8 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 7978a1a7f5f..7efc0ca2da2 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -41,7 +41,7 @@ macro_rules! maybe_whole_expr { return Ok(e); } token::NtPath(path) => { - let path = path.clone(); + let path = (**path).clone(); $p.bump(); return Ok($p.mk_expr( $p.prev_token.span, diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 792f9d9ccce..f1956fb695b 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -1289,7 +1289,7 @@ impl<'a> Parser<'a> { /// so emit a proper diagnostic. // Public for rustfmt usage. pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> { - maybe_whole!(self, NtVis, |x| x); + maybe_whole!(self, NtVis, |x| x.into_inner()); self.expected_tokens.push(TokenType::Keyword(kw::Crate)); if self.is_crate_vis() { diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index c105fbfaee0..b45bca3d2e0 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -118,7 +118,7 @@ impl<'a> Parser<'a> { token::NtBlock(self.collect_tokens_no_attrs(|this| this.parse_block())?) } NonterminalKind::Stmt => match self.parse_stmt(ForceCollect::Yes)? { - Some(s) => token::NtStmt(s), + Some(s) => token::NtStmt(P(s)), None => { return Err(self.struct_span_err(self.token.span, "expected a statement")); } @@ -161,11 +161,11 @@ impl<'a> Parser<'a> { return Err(self.struct_span_err(self.token.span, msg)); } NonterminalKind::Path => token::NtPath( - self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?, + P(self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?), ), NonterminalKind::Meta => token::NtMeta(P(self.parse_attr_item(true)?)), NonterminalKind::Vis => token::NtVis( - self.collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?, + P(self.collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?), ), NonterminalKind::Lifetime => { if self.check_lifetime() { diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 93663a349f5..207ecd00e0c 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -165,7 +165,7 @@ impl<'a> Parser<'a> { maybe_whole!(self, NtPath, |path| { reject_generics_if_mod_style(self, &path); - path + path.into_inner() }); if let token::Interpolated(nt) = &self.token.kind { diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index e3bcd945db7..5b7ae5f7a7b 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -54,7 +54,7 @@ impl<'a> Parser<'a> { stmt.visit_attrs(|stmt_attrs| { attrs.prepend_to_nt_inner(stmt_attrs); }); - return Ok(Some(stmt)); + return Ok(Some(stmt.into_inner())); } Ok(Some(if self.token.is_keyword(kw::Let) { @@ -535,7 +535,7 @@ impl<'a> Parser<'a> { recover: AttemptLocalParseRecovery, ) -> PResult<'a, Option<Stmt>> { // Skip looking for a trailing semicolon when we have an interpolated statement. - maybe_whole!(self, NtStmt, |x| Some(x)); + maybe_whole!(self, NtStmt, |x| Some(x.into_inner())); let Some(mut stmt) = self.parse_stmt_without_recovery(true, ForceCollect::No)? else { return Ok(None); |
