Browse Source

Use collection expressions (performance)

Brandon Thetford 1 year ago
parent
commit
af0912e05b
2 changed files with 18 additions and 16 deletions
  1. 1 1
      Terminal.Gui/Views/HexView.cs
  2. 17 15
      Terminal.Gui/Views/TextView.cs

+ 1 - 1
Terminal.Gui/Views/HexView.cs

@@ -33,7 +33,7 @@ public class HexView : View
     private int bpl;
     private int bpl;
     private CursorVisibility desiredCursorVisibility = CursorVisibility.Default;
     private CursorVisibility desiredCursorVisibility = CursorVisibility.Default;
     private long displayStart, pos;
     private long displayStart, pos;
-    private SortedDictionary<long, byte> edits = new ();
+    private SortedDictionary<long, byte> edits = [];
     private bool firstNibble, leftSide;
     private bool firstNibble, leftSide;
     private Stream source;
     private Stream source;
     private static readonly Rune SpaceCharRune = new (' ');
     private static readonly Rune SpaceCharRune = new (' ');

+ 17 - 15
Terminal.Gui/Views/TextView.cs

@@ -4500,12 +4500,12 @@ public class TextView : View
         }
         }
         else
         else
         {
         {
-            _historyText.Add (new List<List<RuneCell>> { new (currentLine) }, CursorPosition);
+            _historyText.Add ([[..currentLine]], CursorPosition);
 
 
             currentLine.RemoveAt (CurrentColumn);
             currentLine.RemoveAt (CurrentColumn);
 
 
             _historyText.Add (
             _historyText.Add (
-                              new List<List<RuneCell>> { new (currentLine) },
+                              [[..currentLine]],
                               CursorPosition,
                               CursorPosition,
                               HistoryText.LineStatus.Replaced
                               HistoryText.LineStatus.Replaced
                              );
                              );
@@ -5070,7 +5070,7 @@ public class TextView : View
         }
         }
 
 
         _historyText.Add (
         _historyText.Add (
-                          new List<List<RuneCell>> { new (GetCurrentLine ()) },
+                          [[..GetCurrentLine ()]],
                           CursorPosition,
                           CursorPosition,
                           HistoryText.LineStatus.Replaced
                           HistoryText.LineStatus.Replaced
                          );
                          );
@@ -5110,7 +5110,7 @@ public class TextView : View
             return;
             return;
         }
         }
 
 
-        _historyText.Add (new List<List<RuneCell>> { new (currentLine) }, CursorPosition);
+        _historyText.Add ([[..currentLine]], CursorPosition);
 
 
         if (currentLine.Count == 0)
         if (currentLine.Count == 0)
         {
         {
@@ -5141,12 +5141,14 @@ public class TextView : View
                 CurrentRow--;
                 CurrentRow--;
                 currentLine = _model.GetLine (CurrentRow);
                 currentLine = _model.GetLine (CurrentRow);
 
 
-                List<List<RuneCell>> removedLine = new () { new List<RuneCell> (currentLine) };
-
-                removedLine.Add (new List<RuneCell> ());
+                List<List<RuneCell>> removedLine =
+                [
+                    [..currentLine],
+                    []
+                ];
 
 
                 _historyText.Add (
                 _historyText.Add (
-                                  new List<List<RuneCell>> (removedLine),
+                                  [..removedLine],
                                   CursorPosition,
                                   CursorPosition,
                                   HistoryText.LineStatus.Removed
                                   HistoryText.LineStatus.Removed
                                  );
                                  );
@@ -5175,7 +5177,7 @@ public class TextView : View
         }
         }
 
 
         _historyText.Add (
         _historyText.Add (
-                          new List<List<RuneCell>> { new (GetCurrentLine ()) },
+                          [[..GetCurrentLine ()]],
                           CursorPosition,
                           CursorPosition,
                           HistoryText.LineStatus.Replaced
                           HistoryText.LineStatus.Replaced
                          );
                          );
@@ -5199,14 +5201,14 @@ public class TextView : View
 
 
         List<RuneCell> currentLine = GetCurrentLine ();
         List<RuneCell> currentLine = GetCurrentLine ();
 
 
-        _historyText.Add (new List<List<RuneCell>> { new (GetCurrentLine ()) }, CursorPosition);
+        _historyText.Add ([[..GetCurrentLine ()]], CursorPosition);
 
 
         if (CurrentColumn == 0)
         if (CurrentColumn == 0)
         {
         {
             DeleteTextBackwards ();
             DeleteTextBackwards ();
 
 
             _historyText.ReplaceLast (
             _historyText.ReplaceLast (
-                                      new List<List<RuneCell>> { new (GetCurrentLine ()) },
+                                      [[..GetCurrentLine ()]],
                                       CursorPosition,
                                       CursorPosition,
                                       HistoryText.LineStatus.Replaced
                                       HistoryText.LineStatus.Replaced
                                      );
                                      );
@@ -5245,7 +5247,7 @@ public class TextView : View
         }
         }
 
 
         _historyText.Add (
         _historyText.Add (
-                          new List<List<RuneCell>> { new (GetCurrentLine ()) },
+                          [[..GetCurrentLine ()]],
                           CursorPosition,
                           CursorPosition,
                           HistoryText.LineStatus.Replaced
                           HistoryText.LineStatus.Replaced
                          );
                          );
@@ -5267,14 +5269,14 @@ public class TextView : View
 
 
         List<RuneCell> currentLine = GetCurrentLine ();
         List<RuneCell> currentLine = GetCurrentLine ();
 
 
-        _historyText.Add (new List<List<RuneCell>> { new (GetCurrentLine ()) }, CursorPosition);
+        _historyText.Add ([[..GetCurrentLine ()]], CursorPosition);
 
 
         if (currentLine.Count == 0 || CurrentColumn == currentLine.Count)
         if (currentLine.Count == 0 || CurrentColumn == currentLine.Count)
         {
         {
             DeleteTextForwards ();
             DeleteTextForwards ();
 
 
             _historyText.ReplaceLast (
             _historyText.ReplaceLast (
-                                      new List<List<RuneCell>> { new (GetCurrentLine ()) },
+                                      [[..GetCurrentLine ()]],
                                       CursorPosition,
                                       CursorPosition,
                                       HistoryText.LineStatus.Replaced
                                       HistoryText.LineStatus.Replaced
                                      );
                                      );
@@ -5304,7 +5306,7 @@ public class TextView : View
         }
         }
 
 
         _historyText.Add (
         _historyText.Add (
-                          new List<List<RuneCell>> { new (GetCurrentLine ()) },
+                          [[..GetCurrentLine ()]],
                           CursorPosition,
                           CursorPosition,
                           HistoryText.LineStatus.Replaced
                           HistoryText.LineStatus.Replaced
                          );
                          );