@@ -68,9 +68,9 @@ pub struct MarkFrame<'a> {
6868
6969#[ derive( Debug ) ]
7070pub ( super ) enum DepNodeColor {
71- Unknown ,
72- Red ,
7371 Green ( DepNodeIndex ) ,
72+ Red ,
73+ Unknown ,
7474}
7575
7676pub ( crate ) struct DepGraphData < D : Deps > {
@@ -1315,8 +1315,10 @@ pub(super) struct DepNodeColorMap {
13151315 sync : bool ,
13161316}
13171317
1318- const COMPRESSED_UNKNOWN : u32 = u32:: MAX ;
1319- const COMPRESSED_RED : u32 = u32:: MAX - 1 ;
1318+ // The values here are chosen to optimize `DepNodeColorMap::get`. All values below
1319+ // `COMPRESSED_UNKNOWN` are green.
1320+ const COMPRESSED_UNKNOWN : u32 = u32:: MAX - 1 ;
1321+ const COMPRESSED_RED : u32 = u32:: MAX ;
13201322
13211323impl DepNodeColorMap {
13221324 fn new ( size : usize ) -> DepNodeColorMap {
@@ -1366,10 +1368,15 @@ impl DepNodeColorMap {
13661368
13671369 #[ inline]
13681370 pub ( super ) fn get ( & self , index : SerializedDepNodeIndex ) -> DepNodeColor {
1369- match self . values [ index] . load ( Ordering :: Acquire ) {
1370- COMPRESSED_UNKNOWN => DepNodeColor :: Unknown ,
1371- COMPRESSED_RED => DepNodeColor :: Red ,
1372- value => DepNodeColor :: Green ( DepNodeIndex :: from_u32 ( value) ) ,
1371+ let value = self . values [ index] . load ( Ordering :: Acquire ) ;
1372+ // The most common case is green, then unknown, then red.
1373+ if value < COMPRESSED_UNKNOWN {
1374+ DepNodeColor :: Green ( DepNodeIndex :: from_u32 ( value) )
1375+ } else if value == COMPRESSED_UNKNOWN {
1376+ DepNodeColor :: Unknown
1377+ } else {
1378+ debug_assert_eq ! ( value, COMPRESSED_RED ) ;
1379+ DepNodeColor :: Red
13731380 }
13741381 }
13751382
0 commit comments