Adding trivial implementations of Span Fill and Clear (#9162)
authorAhson Ahmed Khan <ahsonkhan@users.noreply.github.com>
Fri, 27 Jan 2017 04:33:48 +0000 (20:33 -0800)
committerJan Kotas <jkotas@microsoft.com>
Fri, 27 Jan 2017 04:33:48 +0000 (20:33 -0800)
src/mscorlib/model.xml
src/mscorlib/src/System/Span.cs

index 09a9ba8..324c8b5 100644 (file)
       <Member Name="Slice(System.Int32,System.Int32)" />
       <Member Name="Equals(System.Object)" />
       <Member Name="DangerousCreate(System.Object,T@,System.Int32)" />
+      <Member Name="Clear" />
+      <Member Name="Fill(T)" />
       <Member Name="GetHashCode" />
       <Member Name="CopyTo(System.Span&lt;T&gt;)" />
       <Member Name="TryCopyTo(System.Span&lt;T&gt;)" />
index 19e21c0..a6e46d5 100644 (file)
@@ -227,6 +227,30 @@ namespace System
         }
 
         /// <summary>
+        /// Clears the contents of this span.
+        /// </summary>
+        public void Clear()
+        {
+            // TODO: Optimize - https://github.com/dotnet/coreclr/issues/9161
+            for (int i = 0; i < _length; i++)
+            {
+                this[i] = default(T);
+            }
+        }
+
+        /// <summary>
+        /// Fills the contents of this span with the given value.
+        /// </summary>
+        public void Fill(T value)
+        {
+            // TODO: Optimize - https://github.com/dotnet/coreclr/issues/9161
+            for (int i = 0; i < _length; i++)
+            {
+                this[i] = value;
+            }
+        }
+
+        /// <summary>
         /// Copies the contents of this span into destination span. If the source
         /// and destinations overlap, this method behaves as if the original values in
         /// a temporary location before the destination is overwritten.