Skip to content

Commit

Permalink
Store boxed slices instead of Vec objects in Context (#278)
Browse files Browse the repository at this point in the history
We never resize the unit ranges, units, or sup units that we parsed --
they stay what they were when we instantiated the Context object. As
such, we don't need to store Vec objects, which include a capacity. Do
what we do for the Functions type and just store boxed slices. Doing so
cuts a machine word of each, but also trims heap allocations to the
minimal size required in the process.

Signed-off-by: Daniel Müller <[email protected]>
Co-authored-by: Daniel Müller <[email protected]>
  • Loading branch information
danielocfb and d-e-s-o authored Jul 20, 2023
1 parent dda39c4 commit 390fb45
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ impl<L: LookupContinuation> LookupResult<L> {
/// when performing lookups for many addresses in the same executable.
pub struct Context<R: gimli::Reader> {
sections: Arc<gimli::Dwarf<R>>,
unit_ranges: Vec<UnitRange>,
units: Vec<ResUnit<R>>,
sup_units: Vec<SupUnit<R>>,
unit_ranges: Box<[UnitRange]>,
units: Box<[ResUnit<R>]>,
sup_units: Box<[SupUnit<R>]>,
}

/// The type of `Context` that supports the `new` method.
Expand Down Expand Up @@ -305,9 +305,9 @@ impl<R: gimli::Reader> Context<R> {
};
Ok(Context {
sections,
unit_ranges,
units,
sup_units,
unit_ranges: unit_ranges.into_boxed_slice(),
units: units.into_boxed_slice(),
sup_units: sup_units.into_boxed_slice(),
})
}

Expand Down Expand Up @@ -531,7 +531,7 @@ impl<R: gimli::Reader> Context<R> {
/// Initialize all line data structures. This is used for benchmarks.
#[doc(hidden)]
pub fn parse_lines(&self) -> Result<(), Error> {
for unit in &self.units {
for unit in self.units.iter() {
unit.parse_lines(&self.sections)?;
}
Ok(())
Expand All @@ -540,7 +540,7 @@ impl<R: gimli::Reader> Context<R> {
/// Initialize all function data structures. This is used for benchmarks.
#[doc(hidden)]
pub fn parse_functions(&self) -> Result<(), Error> {
for unit in &self.units {
for unit in self.units.iter() {
unit.parse_functions(self).skip_all_loads()?;
}
Ok(())
Expand All @@ -549,7 +549,7 @@ impl<R: gimli::Reader> Context<R> {
/// Initialize all inlined function data structures. This is used for benchmarks.
#[doc(hidden)]
pub fn parse_inlined_functions(&self) -> Result<(), Error> {
for unit in &self.units {
for unit in self.units.iter() {
unit.parse_inlined_functions(self).skip_all_loads()?;
}
Ok(())
Expand Down

0 comments on commit 390fb45

Please sign in to comment.