Skip to content

Commit

Permalink
Cleaner code using IndexMut instead of get_mut
Browse files Browse the repository at this point in the history
yay nice
  • Loading branch information
bvibber committed Jul 28, 2020
1 parent bdebcac commit 8dd07e8
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,21 +476,14 @@ impl<T> ChunkMap<T> {
panic!("Tried to land a future chunk");
}
self.running -= 1;
let len = self.chunks.len();
let offset = index - self.cursor_out;
if len < offset {
let n = offset - len;
for _ in 0..n {
self.chunks.push_back(None);
}
while offset > self.chunks.len() {
self.chunks.push_back(None);
}
match self.chunks.get_mut(offset) {
Some(mutref) => {
*mutref = Some(chunk);
},
None => {
self.chunks.push_back(Some(chunk));
},
if offset == self.chunks.len() {
self.chunks.push_back(Some(chunk));
} else {
self.chunks[offset] = Some(chunk);
}
}

Expand Down

0 comments on commit 8dd07e8

Please sign in to comment.