提交 c2ce421b 编写于 作者: N Neal Gafter

Minor changes per code review.

上级 d46f75ae
...@@ -386,7 +386,7 @@ out ImmutableArray<(BoundExpression, BoundDagTemp)> bindings) ...@@ -386,7 +386,7 @@ out ImmutableArray<(BoundExpression, BoundDagTemp)> bindings)
/// when an assertion fails (it is unaffected by exception filters on enclosing frames). /// when an assertion fails (it is unaffected by exception filters on enclosing frames).
/// </summary> /// </summary>
[Conditional("DEBUG")] [Conditional("DEBUG")]
private void Assert(bool condition, string message = null) private static void Assert(bool condition, string message = null)
{ {
if (!condition) if (!condition)
{ {
...@@ -573,7 +573,7 @@ DagState uniqifyState(DagState state) ...@@ -573,7 +573,7 @@ DagState uniqifyState(DagState state)
workList.Free(); workList.Free();
// Now process the states in topological order, leaves first, and assign a BoundDecisionDag to each DagState. // Now process the states in topological order, leaves first, and assign a BoundDecisionDag to each DagState.
ImmutableArray<DagState> sortedStates = initialState.TopologicallySortedReachableStates; ImmutableArray<DagState> sortedStates = initialState.TopologicallySortedReachableStates();
Debug.Assert(_defaultLabel != null); Debug.Assert(_defaultLabel != null);
var finalStates = PooledDictionary<LabelSymbol, BoundDecisionDag>.GetInstance(); var finalStates = PooledDictionary<LabelSymbol, BoundDecisionDag>.GetInstance();
finalStates.Add(_defaultLabel, defaultDecision); finalStates.Add(_defaultLabel, defaultDecision);
...@@ -935,27 +935,24 @@ public DagState(ImmutableArray<PartialCaseDecision> cases) ...@@ -935,27 +935,24 @@ public DagState(ImmutableArray<PartialCaseDecision> cases)
public BoundDagDecision SelectedDecision; public BoundDagDecision SelectedDecision;
public DagState TrueBranch, FalseBranch; public DagState TrueBranch, FalseBranch;
public ImmutableArray<DagState> TopologicallySortedReachableStates public ImmutableArray<DagState> TopologicallySortedReachableStates()
{ {
get // A successor function used to topologically sort the DagState set.
IEnumerable<DagState> succ(DagState state)
{ {
// A successor function used to topologically sort the DagState set. if (state.TrueBranch != null)
IEnumerable<DagState> succ(DagState state)
{ {
if (state.TrueBranch != null) yield return state.TrueBranch;
{
yield return state.TrueBranch;
}
if (state.FalseBranch != null)
{
yield return state.FalseBranch;
}
} }
// Now process the states in topological order, leaves first, and assign a BoundDecisionDag to each DagState. if (state.FalseBranch != null)
return TopologicalSort.IterativeSort<DagState>(SpecializedCollections.SingletonEnumerable<DagState>(this), succ); {
yield return state.FalseBranch;
}
} }
// Now process the states in topological order, leaves first, and assign a BoundDecisionDag to each DagState.
return TopologicalSort.IterativeSort<DagState>(SpecializedCollections.SingletonEnumerable<DagState>(this), succ);
} }
// After the entire graph of DagState objects is complete, we translate each into its Dag. // After the entire graph of DagState objects is complete, we translate each into its Dag.
...@@ -987,7 +984,7 @@ internal BoundDagDecision ComputeSelectedDecision() ...@@ -987,7 +984,7 @@ internal BoundDagDecision ComputeSelectedDecision()
/// </summary> /// </summary>
internal string Dump() internal string Dump()
{ {
var allStates = this.TopologicallySortedReachableStates; var allStates = this.TopologicallySortedReachableStates();
var stateIdentifierMap = PooledDictionary<DagState, int>.GetInstance(); var stateIdentifierMap = PooledDictionary<DagState, int>.GetInstance();
for (int i = 0; i < allStates.Length; i++) for (int i = 0; i < allStates.Length; i++)
{ {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Diagnostics; using System.Diagnostics;
using System.Threading; using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Symbols; using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.PooledObjects; using Microsoft.CodeAnalysis.PooledObjects;
...@@ -84,7 +84,7 @@ bool isSubsumed(BoundPatternSwitchLabel switchLabel) ...@@ -84,7 +84,7 @@ bool isSubsumed(BoundPatternSwitchLabel switchLabel)
} }
// If no switch sections are subsumed, just return // If no switch sections are subsumed, just return
if (switchSections.Count(s => s.SwitchLabels.Count(l => isSubsumed(l)) != 0) == 0) if (!switchSections.Any(s => s.SwitchLabels.Any(l => isSubsumed(l))))
{ {
return; return;
} }
......
...@@ -65,7 +65,7 @@ private void ComputeLabelSet(ImmutableArray<BoundDecisionDag> sortedNodes) ...@@ -65,7 +65,7 @@ private void ComputeLabelSet(ImmutableArray<BoundDecisionDag> sortedNodes)
{ {
// Nodes with more than one predecessor are assigned a label // Nodes with more than one predecessor are assigned a label
var hasPredecessor = PooledHashSet<BoundDecisionDag>.GetInstance(); var hasPredecessor = PooledHashSet<BoundDecisionDag>.GetInstance();
void notePreedecesssor(BoundDecisionDag successor) void notePredecessor(BoundDecisionDag successor)
{ {
if (successor != null && !hasPredecessor.Add(successor)) if (successor != null && !hasPredecessor.Add(successor))
{ {
...@@ -92,11 +92,11 @@ void notePreedecesssor(BoundDecisionDag successor) ...@@ -92,11 +92,11 @@ void notePreedecesssor(BoundDecisionDag successor)
_dagNodeLabels[node] = d.Label; _dagNodeLabels[node] = d.Label;
break; break;
case BoundEvaluationPoint e: case BoundEvaluationPoint e:
notePreedecesssor(e.Next); notePredecessor(e.Next);
break; break;
case BoundDecisionPoint p: case BoundDecisionPoint p:
notePreedecesssor(p.WhenTrue); notePredecessor(p.WhenTrue);
notePreedecesssor(p.WhenFalse); notePredecessor(p.WhenFalse);
break; break;
default: default:
throw ExceptionUtilities.UnexpectedValue(node.Kind); throw ExceptionUtilities.UnexpectedValue(node.Kind);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册