Skip to content

Commit

Permalink
Small changes to allow vectors with small chunk size.
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Nov 26, 2021
1 parent 7c9af5a commit 7d1c1eb
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/vector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,12 @@ impl<A> Vector<A> {
/// to grow further.
fn needs_promotion(&self) -> bool {
match &self.vector {
Inline(_, chunk) if chunk.is_full() => true,
Single(_, chunk) if chunk.is_full() => true,
// Prevent the inline array from getting bigger than a single chunk. This means that we
// can always promote `Inline` to `Single`, even when we're configured to have a small
// chunk size. (TODO: it might be better to just never use `Single` in this situation,
// but that's a more invasive change.)
Inline(_, chunk) => chunk.is_full() || chunk.len() + 1 >= CHUNK_SIZE,
Single(_, chunk) => chunk.is_full(),
_ => false,
}
}
Expand Down Expand Up @@ -1396,11 +1400,7 @@ impl<A: Clone> Vector<A> {
return self.push_back(value);
}
assert!(index < self.len());
if if let Inline(_, chunk) = &self.vector {
chunk.is_full()
} else {
false
} {
if matches!(&self.vector, Inline(_, _)) && self.needs_promotion() {
self.promote_inline();
}
match &mut self.vector {
Expand Down

0 comments on commit 7d1c1eb

Please sign in to comment.