Skip to content

Commit 71fef95

Browse files
committed
SparseBitMatrix: add ensure_row helper fn
1 parent 3f0fb4f commit 71fef95

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/librustc_data_structures/bitvec.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,18 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
313313
}
314314
}
315315

316+
fn ensure_row(&mut self, row: R) {
317+
let columns = self.columns;
318+
self.vector
319+
.ensure_contains_elem(row, || BitVector::new(columns));
320+
}
321+
316322
/// Sets the cell at `(row, column)` to true. Put another way, insert
317323
/// `column` to the bitset for `row`.
318324
///
319325
/// Returns true if this changed the matrix, and false otherwise.
320326
pub fn add(&mut self, row: R, column: C) -> bool {
321-
let columns = self.columns;
322-
self.vector
323-
.ensure_contains_elem(row, || BitVector::new(columns));
327+
self.ensure_row(row);
324328
self.vector[row].insert(column)
325329
}
326330

@@ -344,18 +348,14 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
344348
return false;
345349
}
346350

347-
let columns = self.columns;
348-
self.vector
349-
.ensure_contains_elem(write, || BitVector::new(columns));
351+
self.ensure_row(write);
350352
let (bitvec_read, bitvec_write) = self.vector.pick2_mut(read, write);
351353
bitvec_write.merge(bitvec_read)
352354
}
353355

354356
/// Merge a row, `from`, into the `into` row.
355357
pub fn merge_into(&mut self, into: R, from: &BitVector<C>) -> bool {
356-
let columns = self.columns;
357-
self.vector
358-
.ensure_contains_elem(into, || BitVector::new(columns));
358+
self.ensure_row(into);
359359
self.vector[into].merge(from)
360360
}
361361

0 commit comments

Comments
 (0)