diff options
| author | blake2-ppc <blake2-ppc> | 2013-10-05 01:10:27 +0200 |
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-10-05 01:10:27 +0200 |
| commit | 87294c23baacaee17a13d2f7316fffc76239cff5 (patch) | |
| tree | 42c04a0b0f5ddd1e48e10059c099d2e383cc81bd /src | |
| parent | 9344e2a8665ccd8010bd903aab450115de80bf46 (diff) | |
| download | rust-87294c23baacaee17a13d2f7316fffc76239cff5.tar.gz rust-87294c23baacaee17a13d2f7316fffc76239cff5.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/trans/base.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index dea86286279..2c0497283c1 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -92,17 +92,19 @@ use syntax::visit::Visitor; pub use middle::trans::context::task_llcx; -local_data_key!(task_local_insn_key: @~[&'static str]) +local_data_key!(task_local_insn_key: ~[&'static str]) pub fn with_insn_ctxt(blk: &fn(&[&'static str])) { - let opt = local_data::get(task_local_insn_key, |k| k.map_move(|k| *k)); - if opt.is_some() { - blk(*opt.unwrap()); + do local_data::get(task_local_insn_key) |c| { + match c { + Some(ctx) => blk(*ctx), + None => () + } } } pub fn init_insn_ctxt() { - local_data::set(task_local_insn_key, @~[]); + local_data::set(task_local_insn_key, ~[]); } pub struct _InsnCtxt { _x: () } @@ -111,10 +113,9 @@ pub struct _InsnCtxt { _x: () } impl Drop for _InsnCtxt { fn drop(&mut self) { do local_data::modify(task_local_insn_key) |c| { - do c.map_move |ctx| { - let mut ctx = (*ctx).clone(); + do c.map_move |mut ctx| { ctx.pop(); - @ctx + ctx } } } @@ -123,10 +124,9 @@ impl Drop for _InsnCtxt { pub fn push_ctxt(s: &'static str) -> _InsnCtxt { debug2!("new InsnCtxt: {}", s); do local_data::modify(task_local_insn_key) |c| { - do c.map_move |ctx| { - let mut ctx = (*ctx).clone(); + do c.map_move |mut ctx| { ctx.push(s); - @ctx + ctx } } _InsnCtxt { _x: () } |
