public bool AddType(AnalysisValue ns) { if (!ns.IsAlive) { return(false); } bool wasChanged; IAnalysisSet prev; if (TAKE_COPIES) { prev = _types.Clone(); } else { prev = _types; } if (prev.Any(av => !av.IsAlive)) { _types = AnalysisSet.Create(prev.Where(av => av.IsAlive), prev.Comparer).Add(ns, out wasChanged); } else { _types = prev.Add(ns, out wasChanged); } #if FULL_VALIDATION _changeCount += wasChanged ? 1 : 0; // The value doesn't mean anything, we just want to know if a variable is being // updated too often. Validation.Assert(_changeCount < 10000, $"Excessive changes to a variable"); #endif return(wasChanged); }
public bool AddType(AnalysisValue ns) { bool wasChanged; IAnalysisSet prev; if (TAKE_COPIES) { prev = _types.Clone(); } else { prev = _types; } _types = prev.Add(ns, out wasChanged); #if FULL_VALIDATION _changeCount += wasChanged ? 1 : 0; // The value doesn't mean anything, we just want to know if a variable is being // updated too often. Validation.Assert <ChangeCountExceededException>(_changeCount < 10000); #endif return(wasChanged); }
private static void TestImmutableSet(IAnalysisSet emptySet) { int count = emptySet.Count; var projectEntry = CreateProjectEntry(); var value = new TestAnalysisValue(projectEntry); var newSet = emptySet.Add(value.Proxy); Assert.AreNotEqual(emptySet, newSet); Assert.AreEqual(count, emptySet.Count); Assert.AreEqual(count + 1, newSet.Count); bool wasChanged; newSet = emptySet.Add(value.Proxy, out wasChanged); Assert.AreNotEqual(emptySet, newSet); Assert.IsTrue(wasChanged); Assert.AreEqual(count, emptySet.Count); Assert.AreEqual(count + 1, newSet.Count); newSet = emptySet.Union(new[] { value.Proxy }); Assert.AreNotEqual(emptySet, newSet); Assert.AreEqual(count, emptySet.Count); Assert.AreEqual(count + 1, newSet.Count); newSet = emptySet.Union(new[] { value.Proxy }, out wasChanged); Assert.IsTrue(wasChanged); Assert.AreNotEqual(emptySet, newSet); Assert.AreEqual(count, emptySet.Count); Assert.AreEqual(count + 1, newSet.Count); Assert.AreEqual(emptySet, emptySet.Clone()); Assert.IsFalse(emptySet.Contains(value.Proxy)); }