diff --git a/analyzeme/src/stringtable.rs b/analyzeme/src/stringtable.rs index 31890d9..59d93cd 100644 --- a/analyzeme/src/stringtable.rs +++ b/analyzeme/src/stringtable.rs @@ -1,6 +1,5 @@ //! See module-level documentation `measureme::stringtable`. -use byteorder::{BigEndian, ByteOrder, LittleEndian}; use measureme::file_header::{ read_file_header, strip_file_header, CURRENT_FILE_FORMAT_VERSION, FILE_MAGIC_STRINGTABLE_DATA, FILE_MAGIC_STRINGTABLE_INDEX, @@ -10,12 +9,13 @@ use measureme::{Addr, StringId}; use memchr::memchr; use rustc_hash::FxHashMap; use std::borrow::Cow; +use std::convert::TryInto; use std::error::Error; fn deserialize_index_entry(bytes: &[u8]) -> (StringId, Addr) { ( - StringId::new(LittleEndian::read_u32(&bytes[0..4])), - Addr(LittleEndian::read_u32(&bytes[4..8])), + StringId::new(u32::from_le_bytes(bytes[0..4].try_into().unwrap())), + Addr(u32::from_le_bytes(bytes[4..8].try_into().unwrap())), ) } @@ -138,7 +138,7 @@ fn is_utf8_continuation_byte(byte: u8) -> bool { // String IDs in the table data are encoded in big endian format, while string // IDs in the index are encoded in little endian format. Don't mix the two up. fn decode_string_id_from_data(bytes: &[u8]) -> StringId { - let id = BigEndian::read_u32(&bytes[0..4]); + let id = u32::from_be_bytes(bytes[0..4].try_into().unwrap()); // Mask off the `0b10` prefix StringId::new(id & STRING_ID_MASK) } diff --git a/measureme/src/file_header.rs b/measureme/src/file_header.rs index 6fd63f3..8ff4298 100644 --- a/measureme/src/file_header.rs +++ b/measureme/src/file_header.rs @@ -3,7 +3,7 @@ //! number. use crate::serialization::SerializationSink; -use byteorder::{ByteOrder, LittleEndian}; +use std::convert::TryInto; use std::error::Error; pub const CURRENT_FILE_FORMAT_VERSION: u32 = 5; @@ -22,7 +22,7 @@ pub fn write_file_header(s: &S, file_magic: &[u8; 4]) { s.write_atomic(FILE_HEADER_SIZE, |bytes| { bytes[0..4].copy_from_slice(file_magic); - LittleEndian::write_u32(&mut bytes[4..8], CURRENT_FILE_FORMAT_VERSION); + bytes[4..8].copy_from_slice(&CURRENT_FILE_FORMAT_VERSION.to_le_bytes()); }); } @@ -44,7 +44,7 @@ pub fn read_file_header(bytes: &[u8], expected_magic: &[u8; 4]) -> Result &[u8] { diff --git a/measureme/src/profiler.rs b/measureme/src/profiler.rs index 72e4c06..7f11d07 100644 --- a/measureme/src/profiler.rs +++ b/measureme/src/profiler.rs @@ -31,8 +31,7 @@ pub struct Profiler { } impl Profiler { - pub fn new>(path_stem: P) - -> Result, Box> { + pub fn new>(path_stem: P) -> Result, Box> { let paths = ProfilerFiles::new(path_stem.as_ref()); let event_sink = Arc::new(S::from_path(&paths.events_file)?); diff --git a/measureme/src/raw_event.rs b/measureme/src/raw_event.rs index 68ec2ba..d8aac65 100644 --- a/measureme/src/raw_event.rs +++ b/measureme/src/raw_event.rs @@ -1,5 +1,7 @@ use crate::event_id::EventId; use crate::stringtable::StringId; +#[cfg(target_endian = "big")] +use std::convert::TryInto; /// `RawEvent` is how events are stored on-disk. If you change this struct, /// make sure that you increment `file_header::CURRENT_FILE_FORMAT_VERSION`. @@ -117,14 +119,12 @@ impl RawEvent { { // We always emit data as little endian, which we have to do // manually on big endian targets. - use byteorder::{ByteOrder, LittleEndian}; - - LittleEndian::write_u32(&mut bytes[0..], self.event_kind.as_u32()); - LittleEndian::write_u32(&mut bytes[4..], self.event_id.as_u32()); - LittleEndian::write_u32(&mut bytes[8..], self.thread_id); - LittleEndian::write_u32(&mut bytes[12..], self.start_time_lower); - LittleEndian::write_u32(&mut bytes[16..], self.end_time_lower); - LittleEndian::write_u32(&mut bytes[20..], self.start_and_end_upper); + bytes[0..4].copy_from_slice(&self.event_kind.as_u32().to_le_bytes()); + bytes[4..8].copy_from_slice(&self.event_id.as_u32().to_le_bytes()); + bytes[8..12].copy_from_slice(&self.thread_id.to_le_bytes()); + bytes[12..16].copy_from_slice(&self.start_time_lower.to_le_bytes()); + bytes[16..20].copy_from_slice(&self.end_time_lower.to_le_bytes()); + bytes[20..24].copy_from_slice(&self.start_and_end_upper.to_le_bytes()); } } @@ -147,14 +147,13 @@ impl RawEvent { #[cfg(target_endian = "big")] { - use byteorder::{ByteOrder, LittleEndian}; RawEvent { - event_kind: StringId::new(LittleEndian::read_u32(&bytes[0..])), - event_id: EventId::from_u32(LittleEndian::read_u32(&bytes[4..])), - thread_id: LittleEndian::read_u32(&bytes[8..]), - start_time_lower: LittleEndian::read_u32(&bytes[12..]), - end_time_lower: LittleEndian::read_u32(&bytes[16..]), - start_and_end_upper: LittleEndian::read_u32(&bytes[20..]), + event_kind: StringId::new(u32::from_le_bytes(bytes[0..4].try_into().unwrap())), + event_id: EventId::from_u32(u32::from_le_bytes(bytes[4..8].try_into().unwrap())), + thread_id: u32::from_le_bytes(bytes[8..12].try_into().unwrap()), + start_time_lower: u32::from_le_bytes(bytes[12..16].try_into().unwrap()), + end_time_lower: u32::from_le_bytes(bytes[16..20].try_into().unwrap()), + start_and_end_upper: u32::from_le_bytes(bytes[20..24].try_into().unwrap()), } } } diff --git a/measureme/src/stringtable.rs b/measureme/src/stringtable.rs index fa513e4..6fea968 100644 --- a/measureme/src/stringtable.rs +++ b/measureme/src/stringtable.rs @@ -67,7 +67,6 @@ use crate::file_header::{ write_file_header, FILE_MAGIC_STRINGTABLE_DATA, FILE_MAGIC_STRINGTABLE_INDEX, }; use crate::serialization::{Addr, SerializationSink}; -use byteorder::{BigEndian, ByteOrder, LittleEndian}; use std::sync::Arc; /// A `StringId` is used to identify a string in the `StringTable`. It is @@ -190,7 +189,7 @@ impl<'s> StringComponent<'s> { assert!(string_id.0 == string_id.0 & STRING_ID_MASK); let tagged = string_id.0 | (1u32 << 31); - BigEndian::write_u32(&mut bytes[0..4], tagged); + &mut bytes[0..4].copy_from_slice(&tagged.to_be_bytes()); &mut bytes[4..] } } @@ -253,8 +252,8 @@ impl_serializable_string_for_fixed_size!(16); fn serialize_index_entry(sink: &S, id: StringId, addr: Addr) { sink.write_atomic(8, |bytes| { - LittleEndian::write_u32(&mut bytes[0..4], id.0); - LittleEndian::write_u32(&mut bytes[4..8], addr.0); + bytes[0..4].copy_from_slice(&id.0.to_le_bytes()); + bytes[4..8].copy_from_slice(&addr.0.to_le_bytes()); }); }