Skip to content

Commit

Permalink
Avoid cloning the stack on every push_ctxt call in trans
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
blake2-ppc committed Oct 4, 2013
1 parent 9344e2a commit 87294c2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/librustc/middle/trans/base.rs
Expand Up @@ -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: () }
Expand All @@ -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
}
}
}
Expand All @@ -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: () }
Expand Down

5 comments on commit 87294c2

@bors
Copy link
Contributor

@bors bors commented on 87294c2 Oct 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 87294c2 Oct 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging blake2-ppc/rust/trans-no-push-ctxt-clone = 87294c2 into auto

@bors
Copy link
Contributor

@bors bors commented on 87294c2 Oct 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blake2-ppc/rust/trans-no-push-ctxt-clone = 87294c2 merged ok, testing candidate = 8cb3426

@bors
Copy link
Contributor

@bors bors commented on 87294c2 Oct 5, 2013

@bors
Copy link
Contributor

@bors bors commented on 87294c2 Oct 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 8cb3426

Please sign in to comment.