mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Fix confusing push_or_mutate
API
This fixes a bug when recalculating border collapsing for an existing table now. The bug was caused by using `push_or_mutate` which has no effect if there is already a value at the specified index. The fix switches incorrect `push_or_mutate` calls to use `push_or_set` instead. It also renames `push_or_mutate` to `get_mut_or_push` which I think is a less-confusing name for this method.
This commit is contained in:
parent
4bcdbe6d56
commit
4dc9d8b1c5
2 changed files with 11 additions and 9 deletions
|
@ -658,21 +658,22 @@ pub struct ColumnComputedInlineSize {
|
|||
}
|
||||
|
||||
pub trait VecExt<T> {
|
||||
fn push_or_set(&mut self, index: usize, value: T);
|
||||
fn push_or_mutate(&mut self, index: usize, zero: T) -> &mut T;
|
||||
fn push_or_set(&mut self, index: usize, value: T) -> &mut T;
|
||||
fn get_mut_or_push(&mut self, index: usize, zero: T) -> &mut T;
|
||||
}
|
||||
|
||||
impl<T> VecExt<T> for Vec<T> {
|
||||
fn push_or_set(&mut self, index: usize, value: T) {
|
||||
fn push_or_set(&mut self, index: usize, value: T) -> &mut T {
|
||||
if index < self.len() {
|
||||
self[index] = value
|
||||
} else {
|
||||
debug_assert!(index == self.len());
|
||||
self.push(value)
|
||||
}
|
||||
&mut self[index]
|
||||
}
|
||||
|
||||
fn push_or_mutate(&mut self, index: usize, zero: T) -> &mut T {
|
||||
fn get_mut_or_push(&mut self, index: usize, zero: T) -> &mut T {
|
||||
if index >= self.len() {
|
||||
debug_assert!(index == self.len());
|
||||
self.push(zero)
|
||||
|
@ -697,7 +698,7 @@ fn perform_border_collapse_for_row(child_table_row: &mut TableRowFlow,
|
|||
.enumerate() {
|
||||
child_table_row.final_collapsed_borders.inline.push_or_set(i, *this_inline_border);
|
||||
|
||||
let inline_spacing = inline_spacing.push_or_mutate(i, Au(0));
|
||||
let inline_spacing = inline_spacing.get_mut_or_push(i, Au(0));
|
||||
*inline_spacing = cmp::max(*inline_spacing, this_inline_border.width)
|
||||
}
|
||||
|
||||
|
@ -733,7 +734,7 @@ fn perform_border_collapse_for_row(child_table_row: &mut TableRowFlow,
|
|||
.block_end
|
||||
.iter()
|
||||
.enumerate() {
|
||||
let next_block = next_block.push_or_mutate(i, *this_block_border);
|
||||
let next_block = next_block.push_or_set(i, *this_block_border);
|
||||
match next_block_borders {
|
||||
NextBlockCollapsedBorders::FromNextRow(next_block_borders) => {
|
||||
if next_block_borders.len() > i {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue