diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2020-09-16 16:54:58 +0200 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2020-09-16 16:54:58 +0200 |
| commit | 55d4afd2ba93923fa91bb4099ac805de50f4dc6e (patch) | |
| tree | f233fba770ca384261d29da72fe5ad8cdd26bbd8 /src/vtable.rs | |
| parent | 7285c134d101d441cddb9b62d33d4791d1b87dc0 (diff) | |
Remove byteorder dependency
Diffstat (limited to 'src/vtable.rs')
| -rw-r--r-- | src/vtable.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/vtable.rs b/src/vtable.rs index d23b077148e..c58b39c1c82 100644 --- a/src/vtable.rs +++ b/src/vtable.rs @@ -168,18 +168,23 @@ fn build_vtable<'tcx>( } fn write_usize(tcx: TyCtxt<'_>, buf: &mut [u8], idx: usize, num: u64) { - use byteorder::{BigEndian, LittleEndian, WriteBytesExt}; - - let usize_size = tcx + let pointer_size = tcx .layout_of(ParamEnv::reveal_all().and(tcx.types.usize)) .unwrap() .size .bytes() as usize; - let mut target = &mut buf[idx * usize_size..(idx + 1) * usize_size]; + let target = &mut buf[idx * pointer_size..(idx + 1) * pointer_size]; match tcx.data_layout.endian { - rustc_target::abi::Endian::Little => target.write_uint::<LittleEndian>(num, usize_size), - rustc_target::abi::Endian::Big => target.write_uint::<BigEndian>(num, usize_size), + rustc_target::abi::Endian::Little => match pointer_size { + 4 => target.copy_from_slice(&(num as u32).to_le_bytes()), + 8 => target.copy_from_slice(&(num as u64).to_le_bytes()), + _ => todo!("pointer size {} is not yet supported", pointer_size), + }, + rustc_target::abi::Endian::Big => match pointer_size { + 4 => target.copy_from_slice(&(num as u32).to_be_bytes()), + 8 => target.copy_from_slice(&(num as u64).to_be_bytes()), + _ => todo!("pointer size {} is not yet supported", pointer_size), + }, } - .unwrap() } |
