浏览代码

Reference passing to avoid some struct copies

Brandon Thetford 1 年之前
父节点
当前提交
2d2b04b57e

+ 1 - 1
Terminal.Gui/ConsoleDrivers/ConsoleDriver.cs

@@ -520,7 +520,7 @@ public abstract class ConsoleDriver
     /// <param name="foreground">The foreground color.</param>
     /// <param name="background">The background color.</param>
     /// <returns>The attribute for the foreground and background colors.</returns>
-    public virtual Attribute MakeColor (Color foreground, Color background)
+    public virtual Attribute MakeColor (in Color foreground, in Color background)
     {
         // Encode the colors into the int value.
         return new Attribute (

+ 1 - 1
Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs

@@ -835,7 +835,7 @@ internal class CursesDriver : ConsoleDriver
     ///     bits, and the background color is stored in the least significant 4 bits. The Terminal.GUi Color values are
     ///     converted to curses color encoding before being encoded.
     /// </remarks>
-    public override Attribute MakeColor (Color foreground, Color background)
+    public override Attribute MakeColor (in Color foreground, in Color background)
     {
         if (!RunningUnitTests)
         {

+ 3 - 5
Terminal.Gui/Drawing/Attribute.cs

@@ -67,7 +67,7 @@ public readonly struct Attribute : IEquatable<Attribute>, IEqualityOperators<Att
     /// <summary>Initializes a new instance of the <see cref="Attribute"/> struct.</summary>
     /// <param name="foreground">Foreground</param>
     /// <param name="background">Background</param>
-    public Attribute (Color foreground, Color background)
+    public Attribute (in Color foreground, in Color background)
     {
         Foreground = foreground;
         Background = background;
@@ -94,10 +94,8 @@ public readonly struct Attribute : IEquatable<Attribute>, IEqualityOperators<Att
     /// <summary>Initializes a new instance of the <see cref="Attribute"/> struct.</summary>
     /// <param name="foregroundName">Foreground</param>
     /// <param name="backgroundName">Background</param>
-    public Attribute (in ColorName foregroundName, in ColorName backgroundName) : this (
-                                                                                        new Color (foregroundName),
-                                                                                        new Color (backgroundName)
-                                                                                       )
+    public Attribute (in ColorName foregroundName, in ColorName backgroundName)
+        : this (new Color (in foregroundName), new Color (in backgroundName))
     { }
 
     /// <summary>Initializes a new instance of the <see cref="Attribute"/> struct.</summary>