mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Simplify LocalUseMapBuild
.
It has four different `insert` methods, with some duplication. This commit finds the commonality and removes them all.
This commit is contained in:
parent
6ecf80e1ad
commit
ce2f0b4ce9
@ -137,56 +137,22 @@ struct LocalUseMapBuild<'me> {
|
||||
locals_with_use_data: IndexVec<Local, bool>,
|
||||
}
|
||||
|
||||
impl LocalUseMapBuild<'_> {
|
||||
fn insert_def(&mut self, local: Local, location: Location) {
|
||||
Self::insert(
|
||||
self.elements,
|
||||
&mut self.local_use_map.first_def_at[local],
|
||||
&mut self.local_use_map.appearances,
|
||||
location,
|
||||
);
|
||||
}
|
||||
|
||||
fn insert_use(&mut self, local: Local, location: Location) {
|
||||
Self::insert(
|
||||
self.elements,
|
||||
&mut self.local_use_map.first_use_at[local],
|
||||
&mut self.local_use_map.appearances,
|
||||
location,
|
||||
);
|
||||
}
|
||||
|
||||
fn insert_drop(&mut self, local: Local, location: Location) {
|
||||
Self::insert(
|
||||
self.elements,
|
||||
&mut self.local_use_map.first_drop_at[local],
|
||||
&mut self.local_use_map.appearances,
|
||||
location,
|
||||
);
|
||||
}
|
||||
|
||||
fn insert(
|
||||
elements: &DenseLocationMap,
|
||||
first_appearance: &mut Option<AppearanceIndex>,
|
||||
appearances: &mut Appearances,
|
||||
location: Location,
|
||||
) {
|
||||
let point_index = elements.point_from_location(location);
|
||||
let appearance_index =
|
||||
appearances.push(Appearance { point_index, next: *first_appearance });
|
||||
*first_appearance = Some(appearance_index);
|
||||
}
|
||||
}
|
||||
|
||||
impl Visitor<'_> for LocalUseMapBuild<'_> {
|
||||
fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
|
||||
if self.locals_with_use_data[local] {
|
||||
match def_use::categorize(context) {
|
||||
Some(DefUse::Def) => self.insert_def(local, location),
|
||||
Some(DefUse::Use) => self.insert_use(local, location),
|
||||
Some(DefUse::Drop) => self.insert_drop(local, location),
|
||||
_ => (),
|
||||
}
|
||||
if self.locals_with_use_data[local]
|
||||
&& let Some(def_use) = def_use::categorize(context)
|
||||
{
|
||||
let first_appearance = match def_use {
|
||||
DefUse::Def => &mut self.local_use_map.first_def_at[local],
|
||||
DefUse::Use => &mut self.local_use_map.first_use_at[local],
|
||||
DefUse::Drop => &mut self.local_use_map.first_drop_at[local],
|
||||
};
|
||||
let point_index = self.elements.point_from_location(location);
|
||||
let appearance_index = self
|
||||
.local_use_map
|
||||
.appearances
|
||||
.push(Appearance { point_index, next: *first_appearance });
|
||||
*first_appearance = Some(appearance_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user