Skip to content

Commit

Permalink
Write a loopi{} as a while let loop
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Dubois <[email protected]>
  • Loading branch information
jcdubois committed Nov 10, 2023
1 parent 36f42c4 commit 9f07964
Showing 1 changed file with 22 additions and 30 deletions.
52 changes: 22 additions & 30 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,40 +489,32 @@ impl HeatshrinkEncoder {
{
let mut position = end;

loop {
match self.search_index[position] {
Some(next_position) => {
position = next_position;
while let Some(next_position) = self.search_index[position] {
position = next_position;

if position < start {
if position < start {
break;
} else if self.input_buffer[position + match_maxlen]
!= self.input_buffer[end + match_maxlen]
{
continue;
} else {
let mut len = 1;

while len < maxlen {
if self.input_buffer[position + len] != self.input_buffer[end + len] {
break;
} else if self.input_buffer[position + match_maxlen]
!= self.input_buffer[end + match_maxlen]
{
continue;
} else {
let mut len = 1;

while len < maxlen {
if self.input_buffer[position + len] != self.input_buffer[end + len]
{
break;
}
len += 1;
}

if len > match_maxlen {
match_maxlen = len;
match_index = position;
if len == maxlen {
// don't keep searching
break;
}
}
}
len += 1;
}
None => {
break;

if len > match_maxlen {
match_maxlen = len;
match_index = position;
if len == maxlen {
// don't keep searching
break;
}
}
}
}
Expand Down

0 comments on commit 9f07964

Please sign in to comment.