Use &IndexSlice
instead of &IndexVec
where possible
All the same reasons as for `[T]`: more general, less pointer chasing, and `&mut IndexSlice` emphasizes that it doesn't change *length*.
This commit is contained in:
parent
a93bcdc307
commit
a2ee7592d6
42 changed files with 168 additions and 118 deletions
|
@ -10,7 +10,7 @@
|
|||
//! <https://www.cs.princeton.edu/courses/archive/spr03/cs423/download/dominators.pdf>
|
||||
|
||||
use super::ControlFlowGraph;
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::vec::{Idx, IndexSlice, IndexVec};
|
||||
use std::cmp::Ordering;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -256,10 +256,10 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
|
|||
/// where `+>` is a proper ancestor and `*>` is just an ancestor.
|
||||
#[inline]
|
||||
fn eval(
|
||||
ancestor: &mut IndexVec<PreorderIndex, PreorderIndex>,
|
||||
ancestor: &mut IndexSlice<PreorderIndex, PreorderIndex>,
|
||||
lastlinked: Option<PreorderIndex>,
|
||||
semi: &IndexVec<PreorderIndex, PreorderIndex>,
|
||||
label: &mut IndexVec<PreorderIndex, PreorderIndex>,
|
||||
semi: &IndexSlice<PreorderIndex, PreorderIndex>,
|
||||
label: &mut IndexSlice<PreorderIndex, PreorderIndex>,
|
||||
node: PreorderIndex,
|
||||
) -> PreorderIndex {
|
||||
if is_processed(node, lastlinked) {
|
||||
|
@ -277,10 +277,10 @@ fn is_processed(v: PreorderIndex, lastlinked: Option<PreorderIndex>) -> bool {
|
|||
|
||||
#[inline]
|
||||
fn compress(
|
||||
ancestor: &mut IndexVec<PreorderIndex, PreorderIndex>,
|
||||
ancestor: &mut IndexSlice<PreorderIndex, PreorderIndex>,
|
||||
lastlinked: Option<PreorderIndex>,
|
||||
semi: &IndexVec<PreorderIndex, PreorderIndex>,
|
||||
label: &mut IndexVec<PreorderIndex, PreorderIndex>,
|
||||
semi: &IndexSlice<PreorderIndex, PreorderIndex>,
|
||||
label: &mut IndexSlice<PreorderIndex, PreorderIndex>,
|
||||
v: PreorderIndex,
|
||||
) {
|
||||
assert!(is_processed(v, lastlinked));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use super::{DirectedGraph, WithNumNodes, WithStartNode, WithSuccessors};
|
||||
use rustc_index::bit_set::BitSet;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_index::vec::{IndexSlice, IndexVec};
|
||||
use std::ops::ControlFlow;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -31,7 +31,7 @@ fn post_order_walk<G: DirectedGraph + WithSuccessors + WithNumNodes>(
|
|||
graph: &G,
|
||||
node: G::Node,
|
||||
result: &mut Vec<G::Node>,
|
||||
visited: &mut IndexVec<G::Node, bool>,
|
||||
visited: &mut IndexSlice<G::Node, bool>,
|
||||
) {
|
||||
struct PostOrderFrame<Node, Iter> {
|
||||
node: Node,
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
use crate::fx::FxHashSet;
|
||||
use crate::graph::vec_graph::VecGraph;
|
||||
use crate::graph::{DirectedGraph, GraphSuccessors, WithNumEdges, WithNumNodes, WithSuccessors};
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
use rustc_index::vec::{Idx, IndexSlice, IndexVec};
|
||||
use std::ops::Range;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -43,7 +43,7 @@ impl<N: Idx, S: Idx + Ord> Sccs<N, S> {
|
|||
SccsConstruction::construct(graph)
|
||||
}
|
||||
|
||||
pub fn scc_indices(&self) -> &IndexVec<N, S> {
|
||||
pub fn scc_indices(&self) -> &IndexSlice<N, S> {
|
||||
&self.scc_indices
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ impl<S: Idx> SccData<S> {
|
|||
self.ranges.len()
|
||||
}
|
||||
|
||||
pub fn ranges(&self) -> &IndexVec<S, Range<usize>> {
|
||||
pub fn ranges(&self) -> &IndexSlice<S, Range<usize>> {
|
||||
&self.ranges
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue