Rename ObjSections::count -> len

This commit is contained in:
Luke Street 2024-06-09 16:10:34 -06:00
parent 46cf0be183
commit 4dd2ebf85a
5 changed files with 9 additions and 7 deletions

View File

@ -18,7 +18,7 @@ struct VisitedAddresses {
impl VisitedAddresses {
pub fn new(obj: &ObjInfo) -> Self {
let mut inner = Vec::with_capacity(obj.sections.count());
let mut inner = Vec::with_capacity(obj.sections.len());
for (_, section) in obj.sections.iter() {
if section.kind == ObjSectionKind::Code {
let size = (section.size / 4) as usize;

View File

@ -51,7 +51,9 @@ impl ObjSections {
self.sections.iter_mut().enumerate()
}
pub fn count(&self) -> usize { self.sections.len() }
pub fn len(&self) -> usize { self.sections.len() }
pub fn is_empty(&self) -> bool { self.sections.is_empty() }
pub fn next_section_index(&self) -> usize { self.sections.len() }

View File

@ -652,7 +652,7 @@ where R: BufRead + ?Sized {
"Section out of bounds: {} (index {}), object has {} sections",
name,
index,
obj.sections.count()
obj.sections.len()
);
};
if obj_section.rename(name.clone()).is_err() {

View File

@ -396,7 +396,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
}
writer.reserve_null_section_index();
let mut out_sections: Vec<OutSection> = Vec::with_capacity(obj.sections.count());
let mut out_sections: Vec<OutSection> = Vec::with_capacity(obj.sections.len());
for (_, section) in obj.sections.iter() {
let name = writer.add_section_name(section.name.as_bytes());
let index = writer.reserve_section_index();
@ -411,7 +411,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
});
}
let mut rela_names: Vec<String> = vec![Default::default(); obj.sections.count()];
let mut rela_names: Vec<String> = vec![Default::default(); obj.sections.len()];
for (((_, section), out_section), rela_name) in
obj.sections.iter().zip(&mut out_sections).zip(&mut rela_names)
{
@ -630,7 +630,7 @@ pub fn write_elf(obj: &ObjInfo, export_all: bool) -> Result<Vec<u8>> {
writer.reserve_file_header();
if obj.kind == ObjKind::Executable {
writer.reserve_program_headers(obj.sections.count() as u32);
writer.reserve_program_headers(obj.sections.len() as u32);
}
for ((_, section), out_section) in obj.sections.iter().zip(&mut out_sections) {

View File

@ -710,7 +710,7 @@ fn trim_split_alignment(obj: &mut ObjInfo) -> Result<()> {
/// Trim splits if they contain linker generated symbols.
fn trim_linker_generated_symbols(obj: &mut ObjInfo) -> Result<()> {
for section_index in 0..obj.sections.count() {
for section_index in 0..obj.sections.len() {
let section_end = end_for_section(obj, section_index)?;
let section = &mut obj.sections[section_index];
if section.address as u32 + section.size as u32 == section_end.address {