Skip to content

Commit 686d27c

Browse files
committed
Pass symbols to ExtCtxt::std_path instead of strings.
Because this function is hot.
1 parent 691117b commit 686d27c

File tree

12 files changed

+71
-47
lines changed

12 files changed

+71
-47
lines changed

src/libsyntax/ext/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,10 @@ impl<'a> ExtCtxt<'a> {
969969
pub fn ident_of(&self, st: &str) -> ast::Ident {
970970
ast::Ident::from_str(st)
971971
}
972-
pub fn std_path(&self, components: &[&str]) -> Vec<ast::Ident> {
972+
pub fn std_path(&self, components: &[Symbol]) -> Vec<ast::Ident> {
973973
let def_site = DUMMY_SP.apply_mark(self.current_expansion.mark);
974974
iter::once(Ident::new(keywords::DollarCrate.name(), def_site))
975-
.chain(components.iter().map(|s| self.ident_of(s)))
975+
.chain(components.iter().map(|&s| Ident::with_empty_ctxt(s)))
976976
.collect()
977977
}
978978
pub fn name_of(&self, st: &str) -> ast::Name {

src/libsyntax/ext/build.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::attr;
33
use crate::source_map::{dummy_spanned, respan, Spanned};
44
use crate::ext::base::ExtCtxt;
55
use crate::ptr::P;
6-
use crate::symbol::{Symbol, keywords};
6+
use crate::symbol::{Symbol, keywords, sym};
77
use crate::ThinVec;
88

99
use rustc_target::spec::abi::Abi;
@@ -429,7 +429,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
429429
self.ty_path(
430430
self.path_all(DUMMY_SP,
431431
true,
432-
self.std_path(&["option", "Option"]),
432+
self.std_path(&[sym::option, sym::Option]),
433433
vec![ast::GenericArg::Type(ty)],
434434
Vec::new()))
435435
}
@@ -735,7 +735,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
735735
self.expr(sp, ast::ExprKind::Array(exprs))
736736
}
737737
fn expr_vec_ng(&self, sp: Span) -> P<ast::Expr> {
738-
self.expr_call_global(sp, self.std_path(&["vec", "Vec", "new"]),
738+
self.expr_call_global(sp, self.std_path(&[sym::vec, sym::Vec, sym::new]),
739739
Vec::new())
740740
}
741741
fn expr_vec_slice(&self, sp: Span, exprs: Vec<P<ast::Expr>>) -> P<ast::Expr> {
@@ -751,12 +751,12 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
751751

752752

753753
fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
754-
let some = self.std_path(&["option", "Option", "Some"]);
754+
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
755755
self.expr_call_global(sp, some, vec![expr])
756756
}
757757

758758
fn expr_none(&self, sp: Span) -> P<ast::Expr> {
759-
let none = self.std_path(&["option", "Option", "None"]);
759+
let none = self.std_path(&[sym::option, sym::Option, sym::None]);
760760
let none = self.path_global(sp, none);
761761
self.expr_path(none)
762762
}
@@ -780,7 +780,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
780780
let expr_loc_ptr = self.expr_addr_of(span, expr_loc_tuple);
781781
self.expr_call_global(
782782
span,
783-
self.std_path(&["rt", "begin_panic"]),
783+
self.std_path(&[sym::rt, sym::begin_panic]),
784784
vec![
785785
self.expr_str(span, msg),
786786
expr_loc_ptr])
@@ -791,19 +791,19 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
791791
}
792792

793793
fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
794-
let ok = self.std_path(&["result", "Result", "Ok"]);
794+
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
795795
self.expr_call_global(sp, ok, vec![expr])
796796
}
797797

798798
fn expr_err(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
799-
let err = self.std_path(&["result", "Result", "Err"]);
799+
let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
800800
self.expr_call_global(sp, err, vec![expr])
801801
}
802802

803803
fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> {
804-
let ok = self.std_path(&["result", "Result", "Ok"]);
804+
let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]);
805805
let ok_path = self.path_global(sp, ok);
806-
let err = self.std_path(&["result", "Result", "Err"]);
806+
let err = self.std_path(&[sym::result, sym::Result, sym::Err]);
807807
let err_path = self.path_global(sp, err);
808808

809809
let binding_variable = self.ident_of("__try_var");
@@ -867,25 +867,25 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
867867
}
868868

869869
fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
870-
let some = self.std_path(&["option", "Option", "Some"]);
870+
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
871871
let path = self.path_global(span, some);
872872
self.pat_tuple_struct(span, path, vec![pat])
873873
}
874874

875875
fn pat_none(&self, span: Span) -> P<ast::Pat> {
876-
let some = self.std_path(&["option", "Option", "None"]);
876+
let some = self.std_path(&[sym::option, sym::Option, sym::None]);
877877
let path = self.path_global(span, some);
878878
self.pat_path(span, path)
879879
}
880880

881881
fn pat_ok(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
882-
let some = self.std_path(&["result", "Result", "Ok"]);
882+
let some = self.std_path(&[sym::result, sym::Result, sym::Ok]);
883883
let path = self.path_global(span, some);
884884
self.pat_tuple_struct(span, path, vec![pat])
885885
}
886886

887887
fn pat_err(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> {
888-
let some = self.std_path(&["result", "Result", "Err"]);
888+
let some = self.std_path(&[sym::result, sym::Result, sym::Err]);
889889
let path = self.path_global(span, some);
890890
self.pat_tuple_struct(span, path, vec![pat])
891891
}

src/libsyntax_ext/deriving/clone.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::attr;
77
use syntax::ext::base::{Annotatable, ExtCtxt};
88
use syntax::ext::build::AstBuilder;
99
use syntax::ptr::P;
10-
use syntax::symbol::{keywords, sym};
10+
use syntax::symbol::{keywords, Symbol, sym};
1111
use syntax_pos::Span;
1212

1313
pub fn expand_deriving_clone(cx: &mut ExtCtxt<'_>,
@@ -115,7 +115,7 @@ fn cs_clone_shallow(name: &str,
115115
// set the expn ID so we can use the unstable struct.
116116
let span = span.with_ctxt(cx.backtrace());
117117
let assert_path = cx.path_all(span, true,
118-
cx.std_path(&["clone", helper_name]),
118+
cx.std_path(&[sym::clone, Symbol::intern(helper_name)]),
119119
vec![GenericArg::Type(ty)], vec![]);
120120
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
121121
}
@@ -156,7 +156,7 @@ fn cs_clone(name: &str,
156156
-> P<Expr> {
157157
let ctor_path;
158158
let all_fields;
159-
let fn_path = cx.std_path(&["clone", "Clone", "clone"]);
159+
let fn_path = cx.std_path(&[sym::clone, sym::Clone, sym::clone]);
160160
let subcall = |cx: &mut ExtCtxt<'_>, field: &FieldInfo<'_>| {
161161
let args = vec![cx.expr_addr_of(field.span, field.self_.clone())];
162162
cx.expr_call_global(field.span, fn_path.clone(), args)

src/libsyntax_ext/deriving/cmp/eq.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use syntax::ast::{self, Expr, MetaItem, GenericArg};
66
use syntax::ext::base::{Annotatable, ExtCtxt};
77
use syntax::ext::build::AstBuilder;
88
use syntax::ptr::P;
9-
use syntax::symbol::sym;
9+
use syntax::symbol::{Symbol, sym};
1010
use syntax_pos::Span;
1111

1212
pub fn expand_deriving_eq(cx: &mut ExtCtxt<'_>,
@@ -54,7 +54,7 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt<'_>,
5454
// set the expn ID so we can use the unstable struct.
5555
let span = span.with_ctxt(cx.backtrace());
5656
let assert_path = cx.path_all(span, true,
57-
cx.std_path(&["cmp", helper_name]),
57+
cx.std_path(&[sym::cmp, Symbol::intern(helper_name)]),
5858
vec![GenericArg::Type(ty)], vec![]);
5959
stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path)));
6060
}

src/libsyntax_ext/deriving/cmp/ord.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ pub fn ordering_collapsed(cx: &mut ExtCtxt<'_>,
5555

5656
pub fn cs_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
5757
let test_id = cx.ident_of("cmp").gensym();
58-
let equals_path = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"]));
58+
let equals_path = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));
5959

60-
let cmp_path = cx.std_path(&["cmp", "Ord", "cmp"]);
60+
let cmp_path = cx.std_path(&[sym::cmp, sym::Ord, sym::cmp]);
6161

6262
// Builds:
6363
//

src/libsyntax_ext/deriving/cmp/partial_ord.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use syntax::ast::{self, BinOpKind, Expr, MetaItem};
88
use syntax::ext::base::{Annotatable, ExtCtxt};
99
use syntax::ext::build::AstBuilder;
1010
use syntax::ptr::P;
11-
use syntax::symbol::sym;
11+
use syntax::symbol::{Symbol, sym};
1212
use syntax_pos::Span;
1313

1414
pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt<'_>,
@@ -114,11 +114,11 @@ pub fn some_ordering_collapsed(cx: &mut ExtCtxt<'_>,
114114

115115
pub fn cs_partial_cmp(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> P<Expr> {
116116
let test_id = cx.ident_of("cmp").gensym();
117-
let ordering = cx.path_global(span, cx.std_path(&["cmp", "Ordering", "Equal"]));
117+
let ordering = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));
118118
let ordering_expr = cx.expr_path(ordering.clone());
119119
let equals_expr = cx.expr_some(span, ordering_expr);
120120

121-
let partial_cmp_path = cx.std_path(&["cmp", "PartialOrd", "partial_cmp"]);
121+
let partial_cmp_path = cx.std_path(&[sym::cmp, sym::PartialOrd, sym::partial_cmp]);
122122

123123
// Builds:
124124
//
@@ -188,7 +188,8 @@ fn cs_op(less: bool,
188188
span: Span,
189189
substr: &Substructure<'_>) -> P<Expr> {
190190
let ordering_path = |cx: &mut ExtCtxt<'_>, name: &str| {
191-
cx.expr_path(cx.path_global(span, cx.std_path(&["cmp", "Ordering", name])))
191+
cx.expr_path(cx.path_global(
192+
span, cx.std_path(&[sym::cmp, sym::Ordering, Symbol::intern(name)])))
192193
};
193194

194195
let par_cmp = |cx: &mut ExtCtxt<'_>, span, self_f: P<Expr>, other_fs: &[P<Expr>], default| {
@@ -198,19 +199,19 @@ fn cs_op(less: bool,
198199
};
199200

200201
// `PartialOrd::partial_cmp(self.fi, other.fi)`
201-
let cmp_path = cx.expr_path(cx.path_global(span, cx.std_path(&["cmp",
202-
"PartialOrd",
203-
"partial_cmp"])));
202+
let cmp_path = cx.expr_path(cx.path_global(span, cx.std_path(&[sym::cmp,
203+
sym::PartialOrd,
204+
sym::partial_cmp])));
204205
let cmp = cx.expr_call(span,
205206
cmp_path,
206207
vec![cx.expr_addr_of(span, self_f),
207208
cx.expr_addr_of(span, other_f.clone())]);
208209

209210
let default = ordering_path(cx, default);
210211
// `Option::unwrap_or(_, Ordering::Equal)`
211-
let unwrap_path = cx.expr_path(cx.path_global(span, cx.std_path(&["option",
212-
"Option",
213-
"unwrap_or"])));
212+
let unwrap_path = cx.expr_path(cx.path_global(span, cx.std_path(&[sym::option,
213+
sym::Option,
214+
sym::unwrap_or])));
214215
cx.expr_call(span, unwrap_path, vec![cmp, default])
215216
};
216217

@@ -256,9 +257,9 @@ fn cs_op(less: bool,
256257

257258
// `Ordering::then_with(Option::unwrap_or(..), ..)`
258259
let then_with_path = cx.expr_path(cx.path_global(span,
259-
cx.std_path(&["cmp",
260-
"Ordering",
261-
"then_with"])));
260+
cx.std_path(&[sym::cmp,
261+
sym::Ordering,
262+
sym::then_with])));
262263
cx.expr_call(span, then_with_path, vec![par_cmp, cx.lambda0(span, subexpr)])
263264
},
264265
|cx, args| {

src/libsyntax_ext/deriving/default.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use syntax::ast::{Expr, MetaItem};
66
use syntax::ext::base::{Annotatable, DummyResult, ExtCtxt};
77
use syntax::ext::build::AstBuilder;
88
use syntax::ptr::P;
9-
use syntax::symbol::sym;
9+
use syntax::symbol::{keywords, sym};
1010
use syntax::span_err;
1111
use syntax_pos::Span;
1212

@@ -47,7 +47,8 @@ fn default_substructure(cx: &mut ExtCtxt<'_>,
4747
trait_span: Span,
4848
substr: &Substructure<'_>)
4949
-> P<Expr> {
50-
let default_ident = cx.std_path(&["default", "Default", "default"]);
50+
let default_ident = cx.std_path(&[keywords::Default.name(), sym::Default,
51+
keywords::Default.name()]);
5152
let default_call = |span| cx.expr_call_global(span, default_ident.clone(), Vec::new());
5253

5354
return match *substr.fields {

src/libsyntax_ext/deriving/hash.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use syntax::ast::{Expr, MetaItem, Mutability};
66
use syntax::ext::base::{Annotatable, ExtCtxt};
77
use syntax::ext::build::AstBuilder;
88
use syntax::ptr::P;
9+
use syntax::symbol::sym;
910
use syntax_pos::Span;
1011

1112
pub fn expand_deriving_hash(cx: &mut ExtCtxt<'_>,
@@ -60,7 +61,7 @@ fn hash_substructure(cx: &mut ExtCtxt<'_>, trait_span: Span, substr: &Substructu
6061
};
6162
let call_hash = |span, thing_expr| {
6263
let hash_path = {
63-
let strs = cx.std_path(&["hash", "Hash", "hash"]);
64+
let strs = cx.std_path(&[sym::hash, sym::Hash, sym::hash]);
6465

6566
cx.expr_path(cx.path_global(span, strs))
6667
};

src/libsyntax_ext/deriving/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn call_intrinsic(cx: &ExtCtxt<'_>,
150150
mark.set_expn_info(info);
151151
span = span.with_ctxt(SyntaxContext::empty().apply_mark(mark));
152152
}
153-
let path = cx.std_path(&["intrinsics", intrinsic]);
153+
let path = cx.std_path(&[sym::intrinsics, Symbol::intern(intrinsic)]);
154154
let call = cx.expr_call_global(span, path, args);
155155

156156
cx.expr_block(P(ast::Block {

src/libsyntax_ext/env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
2727
let lt = cx.lifetime(sp, keywords::StaticLifetime.ident());
2828
cx.expr_path(cx.path_all(sp,
2929
true,
30-
cx.std_path(&["option", "Option", "None"]),
30+
cx.std_path(&[sym::option, sym::Option, sym::None]),
3131
vec![GenericArg::Type(cx.ty_rptr(sp,
3232
cx.ty_ident(sp,
3333
Ident::with_empty_ctxt(sym::str)),
@@ -37,7 +37,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt<'_>,
3737
}
3838
Ok(s) => {
3939
cx.expr_call_global(sp,
40-
cx.std_path(&["option", "Option", "Some"]),
40+
cx.std_path(&[sym::option, sym::Option, sym::Some]),
4141
vec![cx.expr_str(sp, Symbol::intern(&s))])
4242
}
4343
};

src/libsyntax_ext/format.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'a, 'b> Context<'a, 'b> {
387387
}
388388

389389
fn rtpath(ecx: &ExtCtxt<'_>, s: &str) -> Vec<ast::Ident> {
390-
ecx.std_path(&["fmt", "rt", "v1", s])
390+
ecx.std_path(&[sym::fmt, sym::rt, sym::v1, Symbol::intern(s)])
391391
}
392392

393393
fn build_count(&self, c: parse::Count<'_>) -> P<ast::Expr> {
@@ -644,7 +644,7 @@ impl<'a, 'b> Context<'a, 'b> {
644644
("new_v1_formatted", vec![pieces, args_slice, fmt])
645645
};
646646

647-
let path = self.ecx.std_path(&["fmt", "Arguments", fn_name]);
647+
let path = self.ecx.std_path(&[sym::fmt, sym::Arguments, Symbol::intern(fn_name)]);
648648
self.ecx.expr_call_global(self.macsp, path, fn_args)
649649
}
650650

@@ -675,14 +675,14 @@ impl<'a, 'b> Context<'a, 'b> {
675675
}
676676
}
677677
Count => {
678-
let path = ecx.std_path(&["fmt", "ArgumentV1", "from_usize"]);
678+
let path = ecx.std_path(&[sym::fmt, sym::ArgumentV1, sym::from_usize]);
679679
return ecx.expr_call_global(macsp, path, vec![arg]);
680680
}
681681
};
682682

683-
let path = ecx.std_path(&["fmt", trait_, "fmt"]);
683+
let path = ecx.std_path(&[sym::fmt, Symbol::intern(trait_), sym::fmt]);
684684
let format_fn = ecx.path_global(sp, path);
685-
let path = ecx.std_path(&["fmt", "ArgumentV1", "new"]);
685+
let path = ecx.std_path(&[sym::fmt, sym::ArgumentV1, sym::new]);
686686
ecx.expr_call_global(macsp, path, vec![arg, ecx.expr_path(format_fn)])
687687
}
688688
}

0 commit comments

Comments
 (0)