Reduce struct copy by 1 in ValueTask.GetAwaiter (#22738)
authorBen Adams <thundercat@illyriad.co.uk>
Thu, 21 Feb 2019 07:26:06 +0000 (07:26 +0000)
committerJan Kotas <jkotas@microsoft.com>
Thu, 21 Feb 2019 07:26:06 +0000 (23:26 -0800)
* Reduce struct copy by 1 in ValueTask.GetAwaiter

* Bit more explicit

src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ConfiguredValueTaskAwaitable.cs
src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/ValueTaskAwaiter.cs
src/System.Private.CoreLib/shared/System/Threading/Tasks/ValueTask.cs

index 66ad43e..2011968 100644 (file)
@@ -24,11 +24,11 @@ namespace System.Runtime.CompilerServices
         /// <summary>Initializes the awaitable.</summary>
         /// <param name="value">The wrapped <see cref="ValueTask"/>.</param>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal ConfiguredValueTaskAwaitable(ValueTask value) => _value = value;
+        internal ConfiguredValueTaskAwaitable(in ValueTask value) => _value = value;
 
         /// <summary>Returns an awaiter for this <see cref="ConfiguredValueTaskAwaitable"/> instance.</summary>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public ConfiguredValueTaskAwaiter GetAwaiter() => new ConfiguredValueTaskAwaiter(_value);
+        public ConfiguredValueTaskAwaiter GetAwaiter() => new ConfiguredValueTaskAwaiter(in _value);
 
         /// <summary>Provides an awaiter for a <see cref="ConfiguredValueTaskAwaitable"/>.</summary>
         [StructLayout(LayoutKind.Auto)]
@@ -40,7 +40,7 @@ namespace System.Runtime.CompilerServices
             /// <summary>Initializes the awaiter.</summary>
             /// <param name="value">The value to be awaited.</param>
             [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            internal ConfiguredValueTaskAwaiter(ValueTask value) => _value = value;
+            internal ConfiguredValueTaskAwaiter(in ValueTask value) => _value = value;
 
             /// <summary>Gets whether the <see cref="ConfiguredValueTaskAwaitable"/> has completed.</summary>
             public bool IsCompleted
@@ -130,11 +130,11 @@ namespace System.Runtime.CompilerServices
         /// <summary>Initializes the awaitable.</summary>
         /// <param name="value">The wrapped <see cref="ValueTask{TResult}"/>.</param>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal ConfiguredValueTaskAwaitable(ValueTask<TResult> value) => _value = value;
+        internal ConfiguredValueTaskAwaitable(in ValueTask<TResult> value) => _value = value;
 
         /// <summary>Returns an awaiter for this <see cref="ConfiguredValueTaskAwaitable{TResult}"/> instance.</summary>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public ConfiguredValueTaskAwaiter GetAwaiter() => new ConfiguredValueTaskAwaiter(_value);
+        public ConfiguredValueTaskAwaiter GetAwaiter() => new ConfiguredValueTaskAwaiter(in _value);
 
         /// <summary>Provides an awaiter for a <see cref="ConfiguredValueTaskAwaitable{TResult}"/>.</summary>
         [StructLayout(LayoutKind.Auto)]
@@ -146,7 +146,7 @@ namespace System.Runtime.CompilerServices
             /// <summary>Initializes the awaiter.</summary>
             /// <param name="value">The value to be awaited.</param>
             [MethodImpl(MethodImplOptions.AggressiveInlining)]
-            internal ConfiguredValueTaskAwaiter(ValueTask<TResult> value) => _value = value;
+            internal ConfiguredValueTaskAwaiter(in ValueTask<TResult> value) => _value = value;
 
             /// <summary>Gets whether the <see cref="ConfiguredValueTaskAwaitable{TResult}"/> has completed.</summary>
             public bool IsCompleted
index 56d8bca..a56911f 100644 (file)
@@ -33,7 +33,7 @@ namespace System.Runtime.CompilerServices
         /// <summary>Initializes the awaiter.</summary>
         /// <param name="value">The value to be awaited.</param>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal ValueTaskAwaiter(ValueTask value) => _value = value;
+        internal ValueTaskAwaiter(in ValueTask value) => _value = value;
 
         /// <summary>Gets whether the <see cref="ValueTask"/> has completed.</summary>
         public bool IsCompleted
@@ -116,7 +116,7 @@ namespace System.Runtime.CompilerServices
         /// <summary>Initializes the awaiter.</summary>
         /// <param name="value">The value to be awaited.</param>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        internal ValueTaskAwaiter(ValueTask<TResult> value) => _value = value;
+        internal ValueTaskAwaiter(in ValueTask<TResult> value) => _value = value;
 
         /// <summary>Gets whether the <see cref="ValueTask{TResult}"/> has completed.</summary>
         public bool IsCompleted
index 256d4d7..e9285ce 100644 (file)
@@ -369,7 +369,7 @@ namespace System.Threading.Tasks
         }
 
         /// <summary>Gets an awaiter for this <see cref="ValueTask"/>.</summary>
-        public ValueTaskAwaiter GetAwaiter() => new ValueTaskAwaiter(this);
+        public ValueTaskAwaiter GetAwaiter() => new ValueTaskAwaiter(in this);
 
         /// <summary>Configures an awaiter for this <see cref="ValueTask"/>.</summary>
         /// <param name="continueOnCapturedContext">
@@ -765,7 +765,7 @@ namespace System.Threading.Tasks
 
         /// <summary>Gets an awaiter for this <see cref="ValueTask{TResult}"/>.</summary>
         [MethodImpl(MethodImplOptions.AggressiveInlining)]
-        public ValueTaskAwaiter<TResult> GetAwaiter() => new ValueTaskAwaiter<TResult>(this);
+        public ValueTaskAwaiter<TResult> GetAwaiter() => new ValueTaskAwaiter<TResult>(in this);
 
         /// <summary>Configures an awaiter for this <see cref="ValueTask{TResult}"/>.</summary>
         /// <param name="continueOnCapturedContext">