public override HistoryMemento OnExecute(IHistoryWorkspace historyWorkspace) { SelectionData state = null; SegmentedList <HistoryMemento> actions = new SegmentedList <HistoryMemento>(); if (!historyWorkspace.Selection.IsEmpty) { state = historyWorkspace.Selection.Save(); HistoryMemento memento3 = new DeselectFunction().Execute(historyWorkspace); actions.Add(memento3); } ReplaceDocumentHistoryMemento item = new ReplaceDocumentHistoryMemento(null, null, historyWorkspace); actions.Add(item); CompoundHistoryMemento memento2 = new CompoundHistoryMemento(StaticName, PdnResources.GetImageResource("Icons.MenuImageFlattenIcon.png"), actions); Document document = RetryManager.RunMemorySensitiveOperation <Document>(() => historyWorkspace.Document.Flatten()); base.EnterCriticalRegion(); historyWorkspace.Document = document; if (state != null) { SelectionHistoryMemento newHA = new SelectionHistoryMemento(null, null, historyWorkspace); historyWorkspace.Selection.Restore(state); memento2.AddMemento(newHA); } return(memento2); }
public void FindLast_VerifyDuplicates(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); T?foundItem; Predicate <T?> EqualsDelegate = (T? item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; if (0 < count) { list.Add(beforeList[0]); //[] Verify first item is duplicated expectedItem = beforeList[0]; foundItem = list.FindLast(EqualsDelegate); Assert.Equal(beforeList[0], foundItem); //"Err_2879072qaiadf Verify first item is duplicated FAILED\n" } if (1 < count) { list.Add(beforeList[1]); //[] Verify second item is duplicated expectedItem = beforeList[1]; foundItem = list.FindLast(EqualsDelegate); Assert.Equal(beforeList[1], foundItem); //"Err_4588ajdia Verify second item is duplicated FAILED\n" //[] Verify with match that matches more then one item foundItem = list.FindLast((T item) => { return(item != null && (item.Equals(beforeList[0]) || item.Equals(beforeList[1]))); }); Assert.Equal(beforeList[1], foundItem); //"Err_4489ajodoi Verify with match that matches more then one item FAILED\n" } }
private Rectangle[] ConsolidateRects(Rectangle[] scans) { if (scans.Length == 0) { return(Array.Empty <Rectangle>()); } SegmentedList <Rectangle> cons = new SegmentedList <Rectangle>(); int current = 0; cons.Add(scans[0]); for (int i = 1; i < scans.Length; ++i) { if (scans[i].Left == cons[current].Left && scans[i].Right == cons[current].Right && scans[i].Top == cons[current].Bottom) { Rectangle cc = cons[current]; cc.Height = scans[i].Bottom - cons[current].Top; cons[current] = cc; } else { cons.Add(scans[i]); current = cons.Count - 1; } } return(cons.ToArrayEx()); }
private void Exists_VerifyVanilla(T[] items) { T?expectedItem = default(T); SegmentedList <T?> list = new SegmentedList <T?>(); Predicate <T?> expectedItemDelegate = (T? item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; bool typeNullable = default(T) == null; for (int i = 0; i < items.Length; ++i) { list.Add(items[i]); } //[] Verify Exists returns the correct index for (int i = 0; i < items.Length; ++i) { expectedItem = items[i]; Assert.True(list.Exists(expectedItemDelegate), "Err_282308ahid Verifying Nullable returned FAILED\n"); } //[] Verify Exists returns true if the match returns true on every item Assert.True((0 < items.Length) == list.Exists((T? item) => { return(true); }), "Err_548ahid Verify Exists returns 0 if the match returns true on every item FAILED\n"); //[] Verify Exists returns false if the match returns false on every item Assert.True(!list.Exists((T? item) => { return(false); }), "Err_30848ahidi Verify Exists returns -1 if the match returns false on every item FAILED\n"); //[] Verify with default(T) list.Add(default(T)); Assert.True(list.Exists((T? item) => { return(item == null ? default(T) == null : item.Equals(default(T))); }), "Err_541848ajodi Verify with default(T) FAILED\n"); list.RemoveAt(list.Count - 1); }
private Rectangle[] ConsolidateRects(Rectangle[] scans) { if (scans.Length == 0) { return(Array.Empty <Rectangle>()); } SegmentedList <Rectangle> items = new SegmentedList <Rectangle>(); int num = 0; items.Add(scans[0]); for (int i = 1; i < scans.Length; i++) { Rectangle rectangle = items[num]; if (scans[i].Left == rectangle.Left) { rectangle = items[num]; if (scans[i].Right == rectangle.Right) { rectangle = items[num]; if (scans[i].Top == rectangle.Bottom) { Rectangle rectangle2 = items[num]; rectangle = items[num]; rectangle2.Height = scans[i].Bottom - rectangle.Top; items[num] = rectangle2; continue; } } } items.Add(scans[i]); num = items.Count - 1; } return(items.ToArrayEx <Rectangle>()); }
public void FindLastIndexIntInt_VerifyDuplicates(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); int index; Predicate <T> EqualsDelegate = (T item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; if (0 < count) { list.Add(beforeList[0]); //[] Verify first item is duplicated expectedItem = beforeList[0]; index = list.FindLastIndex(list.Count - 1, list.Count, EqualsDelegate); Assert.Equal(list.Count - 1, index); //"Err_3282iahid Verify first item is duplicated" } if (1 < count) { list.Add(beforeList[1]); //[] Verify second item is duplicated expectedItem = beforeList[1]; index = list.FindLastIndex(list.Count - 1, list.Count, EqualsDelegate); Assert.Equal(list.Count - 1, index); //"Err_29892adewiu Verify second item is duplicated" } }
private HistoryMemento ImportOneLayer(DocumentWorkspace documentWorkspace, BitmapLayer layer) { SegmentedList <HistoryMemento> items = new SegmentedList <HistoryMemento>(); bool flag = true; if (flag && !documentWorkspace.Selection.IsEmpty) { HistoryMemento item = new DeselectFunction().Execute(documentWorkspace); items.Add(item); } if (flag && ((layer.Width > documentWorkspace.Document.Width) || (layer.Height > documentWorkspace.Document.Height))) { HistoryMemento memento3 = this.DoCanvasResize(documentWorkspace, layer.Size); if (memento3 == null) { flag = false; } else { items.Add(memento3); } } if (flag && (layer.Size != documentWorkspace.Document.Size)) { BitmapLayer layer2; try { using (new WaitCursorChanger(documentWorkspace)) { CleanupManager.RequestCleanup(); layer2 = CanvasSizeAction.ResizeLayer(layer, documentWorkspace.Document.Size, AnchorEdge.TopLeft, ColorBgra.White.NewAlpha(0)); } } catch (OutOfMemoryException exception) { ExceptionDialog.ShowErrorDialog(documentWorkspace, PdnResources.GetString("ImportFromFileAction.ImportOneLayer.OutOfMemory"), exception); flag = false; layer2 = null; } if (layer2 != null) { layer.Dispose(); layer = layer2; } } if (flag) { NewLayerHistoryMemento memento4 = new NewLayerHistoryMemento(string.Empty, null, documentWorkspace, documentWorkspace.Document.Layers.Count); documentWorkspace.Document.Layers.Add(layer); items.Add(memento4); } if (flag) { return(new CompoundHistoryMemento(string.Empty, null, items.ToArrayEx <HistoryMemento>())); } this.Rollback(items); return(null); }
public void AddRemoveValues(T[] items) { SegmentedList <T> list = new SegmentedList <T>(items); for (int i = 0; i < items.Length; i++) { list.Add(items[i]); list.Remove(items[i]); list.Add(items[i]); Assert.True(list.Contains(items[i])); //"Should contain item." } }
protected override SegmentedList <PointDouble> TrimShapePath(SegmentedList <PointDouble> tracePoints) { SegmentedList <PointDouble> list = new SegmentedList <PointDouble>(); if (tracePoints.Count > 0) { list.Add(tracePoints[0]); if (tracePoints.Count > 1) { list.Add(tracePoints[tracePoints.Count - 1]); } } return(list); }
public void FindAll_VerifyDuplicates(int count) { SegmentedList <T> list = GenericListFactory(count); for (int i = 0; i < count / 2; i++) { list.Add(list[i]); } SegmentedList <T> beforeList = list.ToSegmentedList(); T? expectedItem = default(T); Predicate <T> EqualsDelegate = (value) => expectedItem == null ? value == null : expectedItem.Equals(value); //[] Verify FindAll returns the correct List with one item for (int i = 0; i < count; ++i) { expectedItem = beforeList[i]; SegmentedList <T> results = list.FindAll(EqualsDelegate); VerifyList(results, beforeList.Where((value) => EqualsDelegate(value)).ToSegmentedList()); } //[] Verify FindAll returns an List with all of the items if the predicate always returns true VerifyList(list.FindAll(_alwaysTrueDelegate), beforeList); //[] Verify FindAll returns an empty List if the match returns false on every item VerifyList(list.FindAll(_alwaysFalseDelegate), new SegmentedList <T>()); }
public void FindIndex_VerifyVanilla(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); int index; Predicate <T> EqualsDefaultDelegate = (T item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; for (int i = 0; i < count; ++i) { list.Add(beforeList[i]); } //[] Verify FinIndex returns the correct index for (int i = 0; i < count; ++i) { expectedItem = beforeList[i]; index = list.FindIndex(EqualsDefaultDelegate); Assert.Equal(i, index); //"Err_282308ahid Expected FindIndex to return the same." } //[] Verify FindIndex returns 0 if the match returns true on every item int expected = count == 0 ? -1 : 0; index = list.FindIndex(_alwaysTrueDelegate); Assert.Equal(expected, index); //"Err_15198ajid Verify FindIndex returns 0 if the match returns true on every item expected" //[] Verify FindIndex returns -1 if the match returns false on every item index = list.FindIndex(_alwaysFalseDelegate); Assert.Equal(-1, index); //"Err_305981ajodd Verify FindIndex returns -1 if the match returns false on every item" }
public void Find_VerifyVanilla(int count) { SegmentedList <T?> list = GenericListFactory(count) !; SegmentedList <T?> beforeList = list.ToSegmentedList(); T?expectedItem = default(T); T?foundItem; Predicate <T?> EqualsDelegate = (T? item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; //[] Verify Find returns the correct index for (int i = 0; i < count; ++i) { expectedItem = beforeList[i]; foundItem = list.Find(EqualsDelegate); Assert.Equal(expectedItem, foundItem); //"Err_282308ahid Verifying value returned from Find FAILED\n" } //[] Verify Find returns the first item if the match returns true on every item foundItem = list.Find(_alwaysTrueDelegate); Assert.Equal(0 < count ? beforeList[0] : default(T), foundItem); //"Err_548ahid Verify Find returns the first item if the match returns true on every item FAILED\n" //[] Verify Find returns T.Default if the match returns false on every item foundItem = list.Find(_alwaysFalseDelegate); Assert.Equal(default(T), foundItem); //"Err_30848ahidi Verify Find returns T.Default if the match returns false on every item FAILED\n" //[] Verify with default(T) list.Add(default(T)); foundItem = list.Find((T? item) => { return(item == null ? default(T) == null : item.Equals(default(T))); }); Assert.Equal(default(T), foundItem); //"Err_541848ajodi Verify with default(T) FAILED\n" list.RemoveAt(list.Count - 1); }
public void TrueForAll_VerifyVanilla(T[] items) { T?expectedItem = default(T); SegmentedList <T> list = new SegmentedList <T>(); Predicate <T> expectedItemDelegate = delegate(T item) { return(expectedItem == null ? item != null : !expectedItem.Equals(item)); }; bool typeNullable = default(T) == null; for (int i = 0; i < items.Length; ++i) { list.Add(items[i]); } //[] Verify TrueForAll looks at every item for (int i = 0; i < items.Length; ++i) { expectedItem = items[i]; Assert.False(list.TrueForAll(expectedItemDelegate)); //"Err_282308ahid Verify TrueForAll looks at every item FAILED\n" } //[] Verify TrueForAll returns true if the match returns true on every item Assert.True(list.TrueForAll(delegate(T item) { return(true); }), "Err_548ahid Verify TrueForAll returns true if the match returns true on every item FAILED\n"); //[] Verify TrueForAll returns false if the match returns false on every item Assert.True((0 == items.Length) == list.TrueForAll(delegate(T item) { return(false); }), "Err_30848ahidi Verify TrueForAll returns " + (0 == items.Length) + " if the match returns false on every item FAILED\n"); }
public void Reverse_RepeatedValues(int listLength, int index, int count) { SegmentedList <T> list = GenericListFactory(1); for (int i = 1; i < listLength; i++) { list.Add(list[0]); } SegmentedList <T> listBefore = list.ToSegmentedList(); list.Reverse(index, count); for (int i = 0; i < index; i++) { Assert.Equal(list[i], listBefore[i]); //"Expect them to be the same." } int j = 0; for (int i = index; i < index + count; i++) { Assert.Equal(list[i], listBefore[index + count - (j + 1)]); //"Expect them to be the same." j++; } for (int i = index + count; i < listBefore.Count; i++) { Assert.Equal(list[i], listBefore[i]); //"Expect them to be the same." } }
public void ForEach_Verify(int count) { SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> visitedItems = new SegmentedList <T>(); Action <T> action = delegate(T item) { visitedItems.Add(item); }; //[] Verify ForEach looks at every item visitedItems.Clear(); list.ForEach(action); VerifyList(list, visitedItems); }
public void ContainsNullWhenReference(T?[] items, T?value) { if ((object?)value != null) { throw new ArgumentException("invalid argument passed to testcase"); } SegmentedList <T?> list = new SegmentedList <T?>(items); list.Add(value); Assert.True(list.Contains(value)); //"Should contain item." }
public void Sort_IComparer_WithDuplicates(int count) { SegmentedList <T> list = GenericListFactory(count); list.Add(list[0]); IComparer <T> comparer = GetIComparer(); list.Sort(comparer); Assert.All(Enumerable.Range(0, count - 2), i => { Assert.True(comparer.Compare(list[i], list[i + 1]) <= 0); }); }
public void Exists_VerifyExceptions(T[] items) { SegmentedList <T> list = new SegmentedList <T>(); Predicate <T> predicate = (T item) => { return(true); }; for (int i = 0; i < items.Length; ++i) { list.Add(items[i]); } //[] Verify Null match Assert.Throws <ArgumentNullException>(() => list.Exists(null !)); //"Err_858ahia Expected null match to throw ArgumentNullException" }
public HistoryMemento ImportMultipleFiles(DocumentWorkspace documentWorkspace, string[] fileNames) { HistoryMemento memento = null; SegmentedList <HistoryMemento> historyMementos = new SegmentedList <HistoryMemento>(); Rectangle empty = Rectangle.Empty; foreach (string str in fileNames) { HistoryMemento item = this.ImportOneFile(documentWorkspace, str, out empty); if (item != null) { historyMementos.Add(item); } else { this.Rollback(historyMementos); historyMementos.Clear(); break; } } if ((empty.Width > 0) && (empty.Height > 0)) { SelectionHistoryMemento memento3 = new SelectionHistoryMemento(null, null, documentWorkspace); historyMementos.Add(memento3); using (documentWorkspace.Selection.UseChangeScope()) { documentWorkspace.Selection.Reset(); documentWorkspace.Selection.SetContinuation(empty.ToRectInt32(), SelectionCombineMode.Replace); documentWorkspace.Selection.CommitContinuation(); } } if (historyMementos.Count > 0) { HistoryMemento[] actions = historyMementos.ToArrayEx <HistoryMemento>(); memento = new CompoundHistoryMemento(StaticName, StaticImage, actions); } return(memento); }
public void FindIndexIntInt_VerifyDuplicates(int count) { T?expectedItem = default(T); SegmentedList <T> list = GenericListFactory(count); SegmentedList <T> beforeList = list.ToSegmentedList(); int index; Predicate <T> EqualsDelegate = delegate(T item) { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; if (0 < count) { list.Add(beforeList[0]); //[] Verify first item is duplicated expectedItem = beforeList[0]; index = list.FindIndex(0, list.Count, EqualsDelegate); Assert.Equal(0, index); //"Err_3282iahid Verify first item is duplicated" //[] Verify first item is duplicated and index=1 expectedItem = beforeList[0]; index = list.FindIndex(1, list.Count - 1, EqualsDelegate); Assert.Equal(count, index); //"Err_8588ahidi Verify first item is duplicated and index=1" } if (1 < count) { list.Add(beforeList[1]); //[] Verify second item is duplicated expectedItem = beforeList[1]; index = list.FindIndex(0, list.Count, EqualsDelegate); Assert.Equal(1, index); //"Err_29892adewiu Verify second item is duplicated" //[] Verify second item is duplicated and index=2 expectedItem = beforeList[1]; index = list.FindIndex(2, list.Count - 2, EqualsDelegate); Assert.Equal(count + 1, index); //"Err_1580ahisdf Verify second item is duplicated and index=2" } }
public void Sort_Comparison_WithDuplicates(int count) { SegmentedList <T> list = GenericListFactory(count); list.Add(list[0]); IComparer <T> iComparer = GetIComparer(); Comparison <T> comparer = ((T first, T second) => { return(iComparer.Compare(first, second)); }); list.Sort(comparer); Assert.All(Enumerable.Range(0, count - 2), i => { Assert.True(iComparer.Compare(list[i], list[i + 1]) <= 0); }); }
public void IndexOf_DefaultValue(IndexOfMethod indexOfMethod, int count, bool frontToBackOrder) { _ = frontToBackOrder; T?defaultValue = default; SegmentedList <T?> list = GenericListFactory(count) !; IndexOfDelegate IndexOf = IndexOfDelegateFromType(indexOfMethod); while (list.Remove(defaultValue)) { count--; } list.Add(defaultValue); Assert.Equal(count, IndexOf(list !, defaultValue !)); }
private void Exists_VerifyDuplicates(T[] items) { T?expectedItem = default(T); SegmentedList <T> list = new SegmentedList <T>(); Predicate <T> expectedItemDelegate = (T item) => { return(expectedItem == null ? item == null : expectedItem.Equals(item)); }; if (0 < items.Length) { for (int i = 0; i < items.Length; ++i) { list.Add(items[i]); } for (int i = 0; i < items.Length && i < 2; ++i) { list.Add(items[i]); } //[] Verify first item is duplicated expectedItem = items[0]; Assert.True(list.Exists(expectedItemDelegate), "Err_2879072qaiadf Verify first item is duplicated FAILED\n"); } if (1 < items.Length) { //[] Verify second item is duplicated expectedItem = items[1]; Assert.True(list.Exists(expectedItemDelegate), "Err_4588ajdia Verify second item is duplicated FAILED\n"); //[] Verify with match that matches more then one item Assert.True(list.Exists((T item) => { return(item != null && (item.Equals(items[0]) || item.Equals(items[1]))); }), "Err_4489ajodoi Verify with match that matches more then one item FAILED\n"); } }
private static void Warmup(ImmutableArray <SourceFile> files) { Console.WriteLine("Warming up..."); var addLock = new object(); var reportLock = new object(); var warmups = new SegmentedList <double>(1 << (int)Math.Ceiling(Math.Log2(files.Length * s_warmupCount))); var nextReport = -1L; var parsed = 0; var total = files.Length * s_warmupCount; var start = Stopwatch.GetTimestamp(); Parallel.ForEach(files, new ParallelOptions { MaxDegreeOfParallelism = s_threadsCount }, (file, _s, idx) => { for (var round = 0; round < s_warmupCount; round++) { var tStart = Stopwatch.GetTimestamp(); _ = LuaSyntaxTree.ParseText(file.Text, path: file.FileName); var tEnd = Stopwatch.GetTimestamp(); lock (addLock) warmups.Add(tEnd - tStart); var ourParsed = Interlocked.Increment(ref parsed); if (nextReport <= Stopwatch.GetTimestamp() && Monitor.TryEnter(reportLock)) { try { var delta = Stopwatch.GetTimestamp() - start; var timePerItem = (double)delta / ourParsed; var remaining = total - ourParsed; var eta = (long)Math.Ceiling(remaining * timePerItem); Console.WriteLine($"Warmup progress: {ourParsed}/{total}. ETA: {TimeSpan.FromTicks(eta)}"); nextReport = Stopwatch.GetTimestamp() + s_reportInterval; } finally { Monitor.Exit(reportLock); } } } }); var statistics = new Statistics(warmups.Take(files.Length * s_warmupCount)); using var writer = new IndentedTextWriter(Console.Out); writer.WriteLine($"Warmup results:"); PrintStatistics(writer, statistics, static d => Duration.Format(ceil(d)));
public void MultipleValues(T[] items, int times) { SegmentedList <T> list = new SegmentedList <T>(items); for (int i = 0; i < times; i++) { list.Add(items[items.Length / 2]); } for (int i = 0; i < times + 1; i++) { Assert.True(list.Contains(items[items.Length / 2])); //"Should contain item." list.Remove(items[items.Length / 2]); } Assert.False(list.Contains(items[items.Length / 2])); //"Should not contain item" }
public void BinarySearch_ForEveryItemWithDuplicates(int count) { if (count > 0) { SegmentedList <T> list = GenericListFactory(count); list.Add(list[0]); list.Sort(); SegmentedList <T> beforeList = list.ToSegmentedList(); Assert.All(Enumerable.Range(0, list.Count), index => { Assert.True(list.BinarySearch(beforeList[index]) >= 0); Assert.True(list.BinarySearch(beforeList[index], GetIComparer()) >= 0); Assert.Equal(beforeList[index], list[index]); }); } }
void IFastSerializable.FromStream(Deserializer deserializer) { base.FromStream(deserializer); // Read in the Memory addresses of each object int addressCount = deserializer.ReadInt(); m_nodeAddresses = new SegmentedList <Address>(SegmentSize, addressCount); for (int i = 0; i < addressCount; i++) { m_nodeAddresses.Add((Address)deserializer.ReadInt64()); } bool is64bit = false; deserializer.TryReadTagged(ref is64bit); Is64Bit = is64bit; }
public void Sort_intintIComparer_WithDuplicates(int count) { SegmentedList <T> unsortedList = GenericListFactory(count); IComparer <T> comparer = GetIComparer(); unsortedList.Add(unsortedList[0]); for (int startIndex = 0; startIndex < count - 2; startIndex++) { for (int sortCount = 2; sortCount < count - startIndex; sortCount++) { SegmentedList <T> list = new SegmentedList <T>(unsortedList); list.Sort(startIndex, sortCount + 1, comparer); for (int i = startIndex; i < sortCount; i++) { Assert.InRange(comparer.Compare(list[i], list[i + 1]), int.MinValue, 1); } } } }
public void AddParse(FileStatistics fileStatistics) { lock (_addLock) { _parseTimes.Add(fileStatistics.ParseStatistics.ParseTime); if (fileStatistics.ParseStatistics.BytesAllocated > 0) { _parseAllocations.Add(fileStatistics.ParseStatistics.BytesAllocated); } if (fileStatistics.TokenStatistics is not null) { _tokenCounts.Add(fileStatistics.TokenStatistics.TokenCount); } if (fileStatistics.FeatureStatistics is not null) { _globalFeatureStatisticsBuilder.Merge(fileStatistics.FeatureStatistics); } } }
protected virtual NodeOperations CreateNodeOperations(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); // iterating tree is very expensive. do it once and cache it to list SegmentedList <SyntaxNode> nodeIterator; using (Logger.LogBlock(FunctionId.Formatting_IterateNodes, cancellationToken)) { const int magicLengthToNodesRatio = 5; var result = new SegmentedList <SyntaxNode>(Math.Max(this.SpanToFormat.Length / magicLengthToNodesRatio, 4)); foreach (var node in _commonRoot.DescendantNodesAndSelf(this.SpanToFormat)) { cancellationToken.ThrowIfCancellationRequested(); result.Add(node); } nodeIterator = result; } // iterate through each operation using index to not create any unnecessary object cancellationToken.ThrowIfCancellationRequested(); List <IndentBlockOperation> indentBlockOperation; using (Logger.LogBlock(FunctionId.Formatting_CollectIndentBlock, cancellationToken)) { indentBlockOperation = AddOperations <IndentBlockOperation>(nodeIterator, (l, n) => _formattingRules.AddIndentBlockOperations(l, n), cancellationToken); } cancellationToken.ThrowIfCancellationRequested(); List <SuppressOperation> suppressOperation; using (Logger.LogBlock(FunctionId.Formatting_CollectSuppressOperation, cancellationToken)) { suppressOperation = AddOperations <SuppressOperation>(nodeIterator, (l, n) => _formattingRules.AddSuppressOperations(l, n), cancellationToken); } cancellationToken.ThrowIfCancellationRequested(); List <AlignTokensOperation> alignmentOperation; using (Logger.LogBlock(FunctionId.Formatting_CollectAlignOperation, cancellationToken)) { var operations = AddOperations <AlignTokensOperation>(nodeIterator, (l, n) => _formattingRules.AddAlignTokensOperations(l, n), cancellationToken); // make sure we order align operation from left to right operations.Sort((o1, o2) => o1.BaseToken.Span.CompareTo(o2.BaseToken.Span)); alignmentOperation = operations; } cancellationToken.ThrowIfCancellationRequested(); List <AnchorIndentationOperation> anchorIndentationOperations; using (Logger.LogBlock(FunctionId.Formatting_CollectAnchorOperation, cancellationToken)) { anchorIndentationOperations = AddOperations <AnchorIndentationOperation>(nodeIterator, (l, n) => _formattingRules.AddAnchorIndentationOperations(l, n), cancellationToken); } return(new NodeOperations(indentBlockOperation, suppressOperation, anchorIndentationOperations, alignmentOperation)); }