diff --git a/crates/libs/metadata/src/blob.rs b/crates/libs/metadata/src/blob.rs index 67e2dc170d..9c2f66e2dc 100644 --- a/crates/libs/metadata/src/blob.rs +++ b/crates/libs/metadata/src/blob.rs @@ -38,7 +38,7 @@ impl Blob { D::decode(self.file, self.read_usize()) } - pub fn try_read(&mut self, expected: usize) -> bool { + pub(crate) fn try_read(&mut self, expected: usize) -> bool { let (value, offset) = self.peek(); if value == expected { self.offset(offset); @@ -48,7 +48,7 @@ impl Blob { } } - pub fn read_modifiers(&mut self) -> Vec { + pub(crate) fn read_modifiers(&mut self) -> Vec { let mut mods = vec![]; loop { let (value, offset) = self.peek(); @@ -68,14 +68,14 @@ impl Blob { value } - pub fn read_str(&mut self) -> &'static str { + pub(crate) fn read_str(&mut self) -> &'static str { let len = self.read_usize(); let value = unsafe { std::str::from_utf8_unchecked(&self.slice[..len]) }; self.offset(len); value } - pub fn read_utf16(self) -> String { + pub(crate) fn read_utf16(self) -> String { let slice = self.slice; if slice.as_ptr().align_offset(std::mem::align_of::()) > 0 { let slice = slice @@ -92,7 +92,7 @@ impl Blob { } } - pub fn read_bool(&mut self) -> bool { + pub(crate) fn read_bool(&mut self) -> bool { // A bool is specified as "a single byte with value 0 (false) or 1 (true)". match self.read_u8() { 0 => false, @@ -101,67 +101,67 @@ impl Blob { } } - pub fn read_i8(&mut self) -> i8 { + pub(crate) fn read_i8(&mut self) -> i8 { let value = i8::from_le_bytes(self[..1].try_into().unwrap()); self.offset(1); value } - pub fn read_u8(&mut self) -> u8 { + pub(crate) fn read_u8(&mut self) -> u8 { let value = u8::from_le_bytes(self[..1].try_into().unwrap()); self.offset(1); value } - pub fn read_i16(&mut self) -> i16 { + pub(crate) fn read_i16(&mut self) -> i16 { let value = i16::from_le_bytes(self[..2].try_into().unwrap()); self.offset(2); value } - pub fn read_u16(&mut self) -> u16 { + pub(crate) fn read_u16(&mut self) -> u16 { let value = u16::from_le_bytes(self[..2].try_into().unwrap()); self.offset(2); value } - pub fn read_i32(&mut self) -> i32 { + pub(crate) fn read_i32(&mut self) -> i32 { let value = i32::from_le_bytes(self[..4].try_into().unwrap()); self.offset(4); value } - pub fn read_u32(&mut self) -> u32 { + pub(crate) fn read_u32(&mut self) -> u32 { let value = u32::from_le_bytes(self[..4].try_into().unwrap()); self.offset(4); value } - pub fn read_i64(&mut self) -> i64 { + pub(crate) fn read_i64(&mut self) -> i64 { let value = i64::from_le_bytes(self[..8].try_into().unwrap()); self.offset(8); value } - pub fn read_u64(&mut self) -> u64 { + pub(crate) fn read_u64(&mut self) -> u64 { let value = u64::from_le_bytes(self[..8].try_into().unwrap()); self.offset(8); value } - pub fn read_f32(&mut self) -> f32 { + pub(crate) fn read_f32(&mut self) -> f32 { let value = f32::from_le_bytes(self[..4].try_into().unwrap()); self.offset(4); value } - pub fn read_f64(&mut self) -> f64 { + pub(crate) fn read_f64(&mut self) -> f64 { let value = f64::from_le_bytes(self[..8].try_into().unwrap()); self.offset(8); value } - pub fn read_integer(&mut self, ty: Type) -> Value { + pub(crate) fn read_integer(&mut self, ty: Type) -> Value { match ty { Type::I8 => Value::I8(self.read_i8()), Type::U8 => Value::U8(self.read_u8()), diff --git a/crates/libs/metadata/src/file.rs b/crates/libs/metadata/src/file.rs index 8d2f9d6d5c..4d13d2c7d2 100644 --- a/crates/libs/metadata/src/file.rs +++ b/crates/libs/metadata/src/file.rs @@ -566,7 +566,7 @@ impl File { Blob::new(self, &self.bytes[offset..offset + blob_size]) } - pub fn list( + pub(crate) fn list( &'static self, row: usize, table: usize, @@ -574,17 +574,21 @@ impl File { ) -> RowIterator { let first = self.usize(row, table, column) - 1; let next = row + 1; - let last = if next < self.table_len(table) { + let last = if next < self.tables[table].len { self.usize(next, table, column) - 1 } else { - self.table_len(table) + self.tables[table].len }; RowIterator::new(self, first..last) } - pub fn equal_range(&'static self, column: usize, value: usize) -> RowIterator { + pub(crate) fn equal_range( + &'static self, + column: usize, + value: usize, + ) -> RowIterator { let mut first = 0; - let mut last = self.table_len(L::TABLE); + let mut last = self.tables[L::TABLE].len; let mut count = last; loop { @@ -616,7 +620,7 @@ impl File { RowIterator::new(self, first..last) } - pub fn lower_bound_of( + fn lower_bound_of( &self, table: usize, mut first: usize, @@ -638,7 +642,7 @@ impl File { first } - pub fn upper_bound_of( + fn upper_bound_of( &self, table: usize, mut first: usize, @@ -660,11 +664,7 @@ impl File { first } - pub fn table_len(&self, table: usize) -> usize { - self.tables[table].len - } - - pub fn table(&'static self) -> RowIterator { + pub(crate) fn table(&'static self) -> RowIterator { RowIterator::new(self, 0..self.tables[R::TABLE].len) } } @@ -800,26 +800,25 @@ impl Column { } } - #[repr(C)] #[derive(Default)] - struct METADATA_HEADER { - signature: u32, - major_version: u16, - minor_version: u16, - reserved: u32, - length: u32, - version: [u8; 20], - flags: u16, - streams: u16, +struct METADATA_HEADER { + signature: u32, + major_version: u16, + minor_version: u16, + reserved: u32, + length: u32, + version: [u8; 20], + flags: u16, + streams: u16, } - const METADATA_SIGNATURE: u32 = 0x424A_5342; +const METADATA_SIGNATURE: u32 = 0x424A_5342; // A coded index (see codes.rs) is a table index that may refer to different tables. The size of the column in memory // must therefore be large enough to hold an index for a row in the largest possible table. This function determines // this size for the given winmd file. - fn coded_index_size(tables: &[usize]) -> usize { +fn coded_index_size(tables: &[usize]) -> usize { fn small(row_count: usize, bits: u8) -> bool { (row_count as u64) < (1u64 << (16 - bits)) } @@ -843,4 +842,4 @@ impl Column { } else { 4 } -} \ No newline at end of file +} diff --git a/crates/libs/metadata/src/row.rs b/crates/libs/metadata/src/row.rs index bfbafaa839..80fd247860 100644 --- a/crates/libs/metadata/src/row.rs +++ b/crates/libs/metadata/src/row.rs @@ -89,7 +89,8 @@ pub trait HasAttributes { impl> HasAttributes for R { fn attributes(&self) -> RowIterator { - self.file().equal_range(0, Into::::into(*self).encode()) + self.file() + .equal_range(0, Into::::into(*self).encode()) } fn find_attribute(&self, name: &str) -> Option { diff --git a/crates/libs/metadata/src/tables.rs b/crates/libs/metadata/src/tables.rs index 57223e5875..043607cfb3 100644 --- a/crates/libs/metadata/src/tables.rs +++ b/crates/libs/metadata/src/tables.rs @@ -173,7 +173,8 @@ impl Field { } pub fn constant(&self) -> Option { - self.file().equal_range(1, HasConstant::Field(*self).encode()) + self.file() + .equal_range(1, HasConstant::Field(*self).encode()) .next() } @@ -265,7 +266,8 @@ impl MethodDef { } pub fn impl_map(&self) -> Option { - self.file().equal_range(1, MemberForwarded::MethodDef(*self).encode()) + self.file() + .equal_range(1, MemberForwarded::MethodDef(*self).encode()) .next() } @@ -356,7 +358,8 @@ impl TypeDef { } pub fn generics(&self) -> RowIterator { - self.file().equal_range(2, TypeOrMethodDef::TypeDef(*self).encode()) + self.file() + .equal_range(2, TypeOrMethodDef::TypeDef(*self).encode()) } pub fn interface_impls(&self) -> RowIterator { @@ -364,7 +367,8 @@ impl TypeDef { } pub fn enclosing_type(&self) -> Option { - self.file().equal_range::(0, self.index() + 1) + self.file() + .equal_range::(0, self.index() + 1) .next() .map(|row| TypeDef(row.row(1))) }