simplify comments compacting logic (PR feedback)

This commit is contained in:
Thierry Berger 2025-02-21 10:23:43 +01:00
parent 64f75b146f
commit 684e7e46c2
No known key found for this signature in database
GPG Key ID: 367278AA7917D517

View File

@ -266,7 +266,6 @@ pub fn compact(module: &mut crate::Module) {
}
// Adjust comments
if let Some(ref mut comments) = module.comments {
log::trace!("adjusting comments");
let crate::Comments {
module: _,
types: ref mut comment_types,
@ -277,50 +276,34 @@ pub fn compact(module: &mut crate::Module) {
global_variables: _,
} = **comments;
log::trace!("adjusting comments for types");
for comment_type_handle in comment_types.keys().cloned().collect::<Vec<_>>() {
if !module_map.types.used(comment_type_handle) {
comment_types.swap_remove(&comment_type_handle);
for (mut comment_type_handle, comment) in std::mem::take(comment_types) {
if !module_map.types.used(comment_type_handle.clone()) {
continue;
}
let mut handle_copy = comment_type_handle;
module_map.types.adjust(&mut handle_copy);
if handle_copy != comment_type_handle {
let comment = comment_types.swap_remove(&comment_type_handle).unwrap();
comment_types.insert(handle_copy, comment);
}
module_map.types.adjust(&mut comment_type_handle);
comment_types.insert(comment_type_handle, comment);
}
log::trace!("adjusting comments for struct members");
for comment_struct_member_handle in
comment_struct_members.keys().cloned().collect::<Vec<_>>()
{
for (mut comment_struct_member_handle, comment) in std::mem::take(comment_struct_members) {
if !module_map.types.used(comment_struct_member_handle.0) {
comment_struct_members.swap_remove(&comment_struct_member_handle);
continue;
}
let mut handle_copy = comment_struct_member_handle.0;
module_map.types.adjust(&mut handle_copy);
if handle_copy != comment_struct_member_handle.0 {
let comment = comment_struct_members
.swap_remove(&comment_struct_member_handle)
.unwrap();
comment_struct_members
.insert((handle_copy, comment_struct_member_handle.1), comment);
}
module_map.types.adjust(&mut comment_struct_member_handle.0);
comment_struct_members.insert(
(
comment_struct_member_handle.0,
comment_struct_member_handle.1,
),
comment,
);
}
log::trace!("adjusting comments for constants");
for comment_constant_handle in comment_constants.keys().cloned().collect::<Vec<_>>() {
for (mut comment_constant_handle, comment) in std::mem::take(comment_constants) {
if !module_map.constants.used(comment_constant_handle) {
comment_constants.swap_remove(&comment_constant_handle);
continue;
}
let mut handle_copy = comment_constant_handle;
module_map.constants.adjust(&mut handle_copy);
if handle_copy != comment_constant_handle {
let comment = comment_constants
.swap_remove(&comment_constant_handle)
.unwrap();
comment_constants.insert(handle_copy, comment);
}
module_map.constants.adjust(&mut comment_constant_handle);
comment_constants.insert(comment_constant_handle, comment);
}
}