Skip to content

Commit 8cb3426

Browse files
committed
auto merge of #9723 : blake2-ppc/rust/trans-no-push-ctxt-clone, r=alexcrichton
Avoid cloning the stack on every `push_ctxt` call in trans Rewrite the use of TLS variable for `push_ctxt` so that it uses a ~[] instead of a @~[]. Before it cloned the whole vector on each push and pop, which is unnecessary.
2 parents c5295f9 + 87294c2 commit 8cb3426

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/librustc/middle/trans/base.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,19 @@ use syntax::visit::Visitor;
9292

9393
pub use middle::trans::context::task_llcx;
9494

95-
local_data_key!(task_local_insn_key: @~[&'static str])
95+
local_data_key!(task_local_insn_key: ~[&'static str])
9696

9797
pub fn with_insn_ctxt(blk: &fn(&[&'static str])) {
98-
let opt = local_data::get(task_local_insn_key, |k| k.map_move(|k| *k));
99-
if opt.is_some() {
100-
blk(*opt.unwrap());
98+
do local_data::get(task_local_insn_key) |c| {
99+
match c {
100+
Some(ctx) => blk(*ctx),
101+
None => ()
102+
}
101103
}
102104
}
103105

104106
pub fn init_insn_ctxt() {
105-
local_data::set(task_local_insn_key, @~[]);
107+
local_data::set(task_local_insn_key, ~[]);
106108
}
107109

108110
pub struct _InsnCtxt { _x: () }
@@ -111,10 +113,9 @@ pub struct _InsnCtxt { _x: () }
111113
impl Drop for _InsnCtxt {
112114
fn drop(&mut self) {
113115
do local_data::modify(task_local_insn_key) |c| {
114-
do c.map_move |ctx| {
115-
let mut ctx = (*ctx).clone();
116+
do c.map_move |mut ctx| {
116117
ctx.pop();
117-
@ctx
118+
ctx
118119
}
119120
}
120121
}
@@ -123,10 +124,9 @@ impl Drop for _InsnCtxt {
123124
pub fn push_ctxt(s: &'static str) -> _InsnCtxt {
124125
debug2!("new InsnCtxt: {}", s);
125126
do local_data::modify(task_local_insn_key) |c| {
126-
do c.map_move |ctx| {
127-
let mut ctx = (*ctx).clone();
127+
do c.map_move |mut ctx| {
128128
ctx.push(s);
129-
@ctx
129+
ctx
130130
}
131131
}
132132
_InsnCtxt { _x: () }

0 commit comments

Comments
 (0)