Skip to content

Commit

Permalink
Remove get_sorted_members from code_gen_util (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
InsertCreativityHere authored Jan 31, 2024
1 parent 9483387 commit e1eb541
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/utils/code_gen_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,3 @@ pub fn get_bit_sequence_size<T: Member>(encoding: Encoding, members: &[&T]) -> u
.filter(|member| !member.is_tagged() && member.data_type().is_optional)
.count()
}

/// Takes a slice of Member references and returns two vectors. One containing the required members
/// and the other containing the tagged members. The tagged vector is sorted by its tags.
pub fn get_sorted_members<'a, T: Member + ?Sized>(members: &[&'a T]) -> (Vec<&'a T>, Vec<&'a T>) {
let (mut tagged, required): (Vec<&T>, Vec<&T>) = members.iter().partition(|member| member.is_tagged());
tagged.sort_by_key(|member| member.tag().unwrap());
(required, tagged)
}
3 changes: 2 additions & 1 deletion src/validators/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ fn tags_are_unique(members: Vec<&impl Member>, diagnostics: &mut Diagnostics) {
// The tagged members must be sorted by value first as we are using windowing to check the
// n + 1 tagged member against the n tagged member. If the tags are sorted by value then
// the windowing will reveal any duplicate tags.
let (_, sorted_tagged_members) = crate::utils::code_gen_util::get_sorted_members(&members);
let mut sorted_tagged_members = members.into_iter().filter(|m| m.is_tagged()).collect::<Vec<_>>();
sorted_tagged_members.sort_by_key(|member| member.tag().expect("tagged member has no tag!"));
sorted_tagged_members.windows(2).for_each(|window| {
if window[0].tag() == window[1].tag() {
Diagnostic::new(Error::CannotHaveDuplicateTag {
Expand Down

0 comments on commit e1eb541

Please sign in to comment.