Skip to content

auto: rustc: Less copy #4795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ pub fn log_fn_time(ccx: @crate_ctxt, +name: ~str, start: time::Timespec,
ccx.stats.fn_times.push({ident: name, time: elapsed});
}

pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv,
pub fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
llty: TypeRef) -> ValueRef {
let llfn: ValueRef = str::as_c_str(name, |buf| {
unsafe {
Expand All @@ -150,7 +150,7 @@ pub fn decl_fn(llmod: ModuleRef, name: ~str, cc: lib::llvm::CallConv,
return llfn;
}

pub fn decl_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef)
pub fn decl_cdecl_fn(llmod: ModuleRef, name: &str, llty: TypeRef)
-> ValueRef {
return decl_fn(llmod, name, lib::llvm::CCallConv, llty);
}
Expand All @@ -164,20 +164,19 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, +name: ~str, llty: TypeRef) ->
return llfn;
}

pub fn get_extern_fn(externs: HashMap<~str, ValueRef>,
pub fn get_extern_fn(externs: ExternMap,
llmod: ModuleRef,
+name: ~str,
name: @str,
cc: lib::llvm::CallConv,
ty: TypeRef) -> ValueRef {
if externs.contains_key_ref(&name) { return externs.get(&name); }
// XXX: Bad copy.
let f = decl_fn(llmod, copy name, cc, ty);
let f = decl_fn(llmod, name, cc, ty);
externs.insert(name, f);
return f;
}

pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
+name: ~str, ty: TypeRef) -> ValueRef {
pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
name: @str, ty: TypeRef) -> ValueRef {
unsafe {
if externs.contains_key_ref(&name) { return externs.get(&name); }
let c = str::as_c_str(name, |buf| {
Expand All @@ -189,9 +188,9 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
}

fn get_simple_extern_fn(cx: block,
externs: HashMap<~str, ValueRef>,
externs: ExternMap,
llmod: ModuleRef,
+name: ~str,
name: @str,
n_args: int) -> ValueRef {
let _icx = cx.insn_ctxt("get_simple_extern_fn");
let ccx = cx.fcx.ccx;
Expand All @@ -201,8 +200,8 @@ pub fn get_extern_const(externs: HashMap<~str, ValueRef>, llmod: ModuleRef,
return get_extern_fn(externs, llmod, name, lib::llvm::CCallConv, t);
}

pub fn trans_foreign_call(cx: block, externs: HashMap<~str, ValueRef>,
llmod: ModuleRef, +name: ~str, args: ~[ValueRef]) ->
pub fn trans_foreign_call(cx: block, externs: ExternMap,
llmod: ModuleRef, name: @str, args: ~[ValueRef]) ->
ValueRef {
let _icx = cx.insn_ctxt("trans_foreign_call");
let n = args.len() as int;
Expand Down Expand Up @@ -474,6 +473,7 @@ pub fn get_res_dtor(ccx: @crate_ctxt, did: ast::def_id,
let class_ty = ty::subst_tps(tcx, substs, None,
ty::lookup_item_type(tcx, parent_id).ty);
let llty = type_of_dtor(ccx, class_ty);
let name = name.to_managed(); // :-(
get_extern_fn(ccx.externs, ccx.llmod, name, lib::llvm::CCallConv,
llty)
}
Expand Down Expand Up @@ -766,7 +766,7 @@ pub fn null_env_ptr(bcx: block) -> ValueRef {

pub fn trans_external_path(ccx: @crate_ctxt, did: ast::def_id, t: ty::t)
-> ValueRef {
let name = csearch::get_symbol(ccx.sess.cstore, did);
let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
match ty::get(t).sty {
ty::ty_fn(_) => {
let llty = type_of_fn_from_ty(ccx, t);
Expand Down
4 changes: 3 additions & 1 deletion src/librustc/middle/trans/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,15 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
}
}

type ExternMap = HashMap<@str, ValueRef>;

// Crate context. Every crate we compile has one of these.
pub struct crate_ctxt {
sess: session::Session,
llmod: ModuleRef,
td: target_data,
tn: type_names,
externs: HashMap<~str, ValueRef>,
externs: ExternMap,
intrinsics: HashMap<~str, ValueRef>,
item_vals: HashMap<ast::node_id, ValueRef>,
exp_map2: resolve::ExportMap2,
Expand Down