Skip to content

Commit 383e3fd

Browse files
committed
use a more efficient vtable representation
[TyDesc, ... methods] -> [destructor, ... methods]
1 parent 50bee30 commit 383e3fd

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/librustc/middle/trans/glue.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -367,17 +367,9 @@ fn make_drop_glue<'a>(bcx: &'a Block<'a>, v0: ValueRef, t: ty::t) -> &'a Block<'
367367
let lluniquevalue = GEPi(bcx, v0, [0, abi::trt_field_box]);
368368
// Only drop the value when it is non-null
369369
with_cond(bcx, IsNotNull(bcx, Load(bcx, lluniquevalue)), |bcx| {
370-
let llvtable = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
371-
372-
// Cast the vtable to a pointer to a pointer to a tydesc.
373-
let llvtable = PointerCast(bcx, llvtable,
374-
ccx.tydesc_type.ptr_to().ptr_to());
375-
let lltydesc = Load(bcx, llvtable);
376-
call_tydesc_glue_full(bcx,
377-
lluniquevalue,
378-
lltydesc,
379-
abi::tydesc_field_drop_glue,
380-
None);
370+
let lldtor_ptr = Load(bcx, GEPi(bcx, v0, [0, abi::trt_field_vtable]));
371+
let lldtor = Load(bcx, lldtor_ptr);
372+
Call(bcx, lldtor, [PointerCast(bcx, lluniquevalue, Type::i8p())], []);
381373
bcx
382374
})
383375
}

src/librustc/middle/trans/meth.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ pub fn make_vtable(ccx: &CrateContext,
498498
unsafe {
499499
let _icx = push_ctxt("meth::make_vtable");
500500

501-
let mut components = ~[ tydesc.tydesc ];
501+
let mut components = ~[tydesc.drop_glue.get().unwrap()];
502502
for &ptr in ptrs.iter() {
503503
components.push(ptr)
504504
}

src/librustc/middle/trans/type_.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl Type {
180180
}
181181

182182
pub fn vtable() -> Type {
183-
Type::array(&Type::i8().ptr_to(), 1)
183+
Type::array(&Type::i8p().ptr_to(), 1)
184184
}
185185

186186
pub fn generic_glue_fn(cx: &CrateContext) -> Type {
@@ -246,13 +246,13 @@ impl Type {
246246
}
247247

248248
pub fn opaque_trait(ctx: &CrateContext, store: ty::TraitStore) -> Type {
249-
let tydesc_ptr = ctx.tydesc_type.ptr_to();
249+
let vtable = Type::glue_fn(Type::i8p()).ptr_to().ptr_to();
250250
let box_ty = match store {
251251
ty::BoxTraitStore => Type::at_box(ctx, Type::i8()),
252252
ty::UniqTraitStore => Type::i8(),
253253
ty::RegionTraitStore(..) => Type::i8()
254254
};
255-
Type::struct_([tydesc_ptr, box_ty.ptr_to()], false)
255+
Type::struct_([vtable, box_ty.ptr_to()], false)
256256
}
257257

258258
pub fn kind(&self) -> TypeKind {

0 commit comments

Comments
 (0)