From af0912e05bef06bb695f40c17a01c3cf631df777 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 25 Feb 2024 20:07:26 -0700 Subject: [PATCH] Use collection expressions (performance) --- Terminal.Gui/Views/HexView.cs | 2 +- Terminal.Gui/Views/TextView.cs | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Terminal.Gui/Views/HexView.cs b/Terminal.Gui/Views/HexView.cs index 474be71b2..18641103e 100644 --- a/Terminal.Gui/Views/HexView.cs +++ b/Terminal.Gui/Views/HexView.cs @@ -33,7 +33,7 @@ public class HexView : View private int bpl; private CursorVisibility desiredCursorVisibility = CursorVisibility.Default; private long displayStart, pos; - private SortedDictionary edits = new (); + private SortedDictionary edits = []; private bool firstNibble, leftSide; private Stream source; private static readonly Rune SpaceCharRune = new (' '); diff --git a/Terminal.Gui/Views/TextView.cs b/Terminal.Gui/Views/TextView.cs index 226fe51bd..64bbb709c 100644 --- a/Terminal.Gui/Views/TextView.cs +++ b/Terminal.Gui/Views/TextView.cs @@ -4500,12 +4500,12 @@ public class TextView : View } else { - _historyText.Add (new List> { new (currentLine) }, CursorPosition); + _historyText.Add ([[..currentLine]], CursorPosition); currentLine.RemoveAt (CurrentColumn); _historyText.Add ( - new List> { new (currentLine) }, + [[..currentLine]], CursorPosition, HistoryText.LineStatus.Replaced ); @@ -5070,7 +5070,7 @@ public class TextView : View } _historyText.Add ( - new List> { new (GetCurrentLine ()) }, + [[..GetCurrentLine ()]], CursorPosition, HistoryText.LineStatus.Replaced ); @@ -5110,7 +5110,7 @@ public class TextView : View return; } - _historyText.Add (new List> { new (currentLine) }, CursorPosition); + _historyText.Add ([[..currentLine]], CursorPosition); if (currentLine.Count == 0) { @@ -5141,12 +5141,14 @@ public class TextView : View CurrentRow--; currentLine = _model.GetLine (CurrentRow); - List> removedLine = new () { new List (currentLine) }; - - removedLine.Add (new List ()); + List> removedLine = + [ + [..currentLine], + [] + ]; _historyText.Add ( - new List> (removedLine), + [..removedLine], CursorPosition, HistoryText.LineStatus.Removed ); @@ -5175,7 +5177,7 @@ public class TextView : View } _historyText.Add ( - new List> { new (GetCurrentLine ()) }, + [[..GetCurrentLine ()]], CursorPosition, HistoryText.LineStatus.Replaced ); @@ -5199,14 +5201,14 @@ public class TextView : View List currentLine = GetCurrentLine (); - _historyText.Add (new List> { new (GetCurrentLine ()) }, CursorPosition); + _historyText.Add ([[..GetCurrentLine ()]], CursorPosition); if (CurrentColumn == 0) { DeleteTextBackwards (); _historyText.ReplaceLast ( - new List> { new (GetCurrentLine ()) }, + [[..GetCurrentLine ()]], CursorPosition, HistoryText.LineStatus.Replaced ); @@ -5245,7 +5247,7 @@ public class TextView : View } _historyText.Add ( - new List> { new (GetCurrentLine ()) }, + [[..GetCurrentLine ()]], CursorPosition, HistoryText.LineStatus.Replaced ); @@ -5267,14 +5269,14 @@ public class TextView : View List currentLine = GetCurrentLine (); - _historyText.Add (new List> { new (GetCurrentLine ()) }, CursorPosition); + _historyText.Add ([[..GetCurrentLine ()]], CursorPosition); if (currentLine.Count == 0 || CurrentColumn == currentLine.Count) { DeleteTextForwards (); _historyText.ReplaceLast ( - new List> { new (GetCurrentLine ()) }, + [[..GetCurrentLine ()]], CursorPosition, HistoryText.LineStatus.Replaced ); @@ -5304,7 +5306,7 @@ public class TextView : View } _historyText.Add ( - new List> { new (GetCurrentLine ()) }, + [[..GetCurrentLine ()]], CursorPosition, HistoryText.LineStatus.Replaced );