Skip to content

Commit 0973521

Browse files
nagisaDavid Wood
authored andcommitted
Unbox create_contribution_adjustor closure
1 parent 27e5af2 commit 0973521

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

thorin/src/package.rs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -215,48 +215,44 @@ pub(crate) fn create_contribution_adjustor<'input, R: 'input>(
215215
cu_index: Option<&'input UnitIndex<R>>,
216216
tu_index: Option<&'input UnitIndex<R>>,
217217
target_section_id: gimli::SectionId,
218-
) -> Box<dyn FnMut(DwarfObject, Option<Contribution>) -> Result<Option<Contribution>> + 'input>
218+
) -> impl FnMut(DwarfObject, Option<Contribution>) -> Result<Option<Contribution>> + 'input
219219
where
220220
R: gimli::Reader,
221221
{
222222
let mut cu_adjustment = 0;
223223
let mut tu_adjustment = 0;
224224

225-
Box::new(
226-
move |identifier: DwarfObject,
227-
contribution: Option<Contribution>|
228-
-> Result<Option<Contribution>> {
229-
let (adjustment, index) = match identifier {
230-
DwarfObject::Compilation(_) => (&mut cu_adjustment, &cu_index),
231-
DwarfObject::Type(_) => (&mut tu_adjustment, &tu_index),
232-
};
233-
match (index, contribution) {
234-
// dwp input with section
235-
(Some(index), Some(contribution)) => {
236-
let idx = identifier.index();
237-
let row_id = index.find(idx).ok_or(Error::UnitNotInIndex(idx))?;
238-
let section = index
239-
.sections(row_id)
240-
.map_err(|e| Error::RowNotInIndex(e, row_id))?
241-
.find(|index_section| index_section.section == target_section_id)
242-
.ok_or(Error::SectionNotInRow)?;
243-
let adjusted_offset: u64 = contribution.offset.0 + *adjustment;
244-
*adjustment += section.size as u64;
245-
246-
Ok(Some(Contribution {
247-
offset: ContributionOffset(adjusted_offset),
248-
size: section.size as u64,
249-
}))
250-
}
251-
// dwp input without section
252-
(Some(_), None) => Ok(None),
253-
// dwo input with section
254-
(None, Some(contribution)) => Ok(Some(contribution)),
255-
// dwo input without section
256-
(None, None) => Ok(None),
225+
move |identifier: DwarfObject,
226+
contribution: Option<Contribution>|
227+
-> Result<Option<Contribution>> {
228+
let (adjustment, index) = match identifier {
229+
DwarfObject::Compilation(_) => (&mut cu_adjustment, &cu_index),
230+
DwarfObject::Type(_) => (&mut tu_adjustment, &tu_index),
231+
};
232+
match (index, contribution) {
233+
// dwp input with section
234+
(Some(index), Some(contribution)) => {
235+
let idx = identifier.index();
236+
let row_id = index.find(idx).ok_or(Error::UnitNotInIndex(idx))?;
237+
let section = index
238+
.sections(row_id)
239+
.map_err(|e| Error::RowNotInIndex(e, row_id))?
240+
.find(|index_section| index_section.section == target_section_id)
241+
.ok_or(Error::SectionNotInRow)?;
242+
let adjusted_offset: u64 = contribution.offset.0 + *adjustment;
243+
*adjustment += section.size as u64;
244+
245+
Ok(Some(Contribution {
246+
offset: ContributionOffset(adjusted_offset),
247+
size: section.size as u64,
248+
}))
257249
}
258-
},
259-
)
250+
// dwp input without section
251+
(Some(_) | None, None) => Ok(contribution),
252+
// dwo input with section, but we aren't adjusting this particular index
253+
(None, Some(_)) => Ok(contribution),
254+
}
255+
}
260256
}
261257

262258
/// Wrapper around `object::write::Object` that keeps track of the section indexes relevant to

0 commit comments

Comments
 (0)