Skip to content

Commit

Permalink
refacto: clean RevisionList cursor skip_while function
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Rosenkranz-Costa committed Dec 20, 2023
1 parent 512bcf0 commit 0dc3982
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
12 changes: 4 additions & 8 deletions src/core/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,10 @@ pub fn refresh(
for (partition, user_chain) in usk.subkeys.iter_mut() {
let master_chain = msk.subkeys.get(partition).expect("at least one key");
// compare against all master subkeys or the last one to remove old rights
let mut master_chain_iter = master_chain
.iter()
.take(if keep_old_rights {
master_chain.len()
} else {
1
})
.peekable();
let mut master_chain_iter = match keep_old_rights {
true => master_chain.iter().take(master_chain.len()).peekable(),
false => master_chain.iter().take(1).peekable(),
};

// 1 - add new master subkeys in user key if any
let user_first_key = user_chain.front().expect("have one key").clone();
Expand Down
16 changes: 5 additions & 11 deletions src/data_struct/revision_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<'a, T> Cursor<'a, T> {
}
}

/// Iterates through new values adding them before the current cursor.
/// Adds a new value in the list before the current cursor.
pub fn prepend(&mut self, new_value: T) {
let Some(mut cursor) = self.cursor_ptr.take() else {
return;
Expand All @@ -174,17 +174,11 @@ impl<'a, T> Cursor<'a, T> {

/// Moves the cursor down the list while the given predicate is true.
pub fn skip_while(&mut self, mut f: impl FnMut(&T) -> bool) {
loop {
if let Some(Some(element)) = &self.cursor_ptr {
{
if !f(&element.data) {
return;
}
}
} else {
return;
while let Some(Some(element)) = &self.cursor_ptr {
match f(&element.data) {
true => self.move_next(),
false => return,
}
self.move_next()
}
}

Expand Down

0 comments on commit 0dc3982

Please sign in to comment.