Updating Buffer.ZeroMemory to call SpanHelpers.ClearWithoutReferences
authorTanner Gooding <tagoo@outlook.com>
Mon, 17 Sep 2018 22:23:13 +0000 (15:23 -0700)
committerTanner Gooding <tagoo@outlook.com>
Tue, 18 Sep 2018 03:26:06 +0000 (20:26 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/2a12f7e1295fa672d81a552d06b8fb17ec7305a8

src/coreclr/src/System.Private.CoreLib/src/System/Buffer.cs

index d9cd453..7f1a657 100644 (file)
@@ -117,10 +117,17 @@ namespace System
             return _ByteLength(array);
         }
 
-        internal static unsafe void ZeroMemory(byte* src, long len)
+        // This is currently used by System.IO.UnmanagedMemoryStream
+        internal static unsafe void ZeroMemory(byte* dest, long len)
         {
-            while (len-- > 0)
-                *(src + len) = 0;
+            Debug.Assert((ulong)(len) == (nuint)(len));
+            ZeroMemory(dest, (nuint)(len));
+        }
+
+        // This method has different signature for x64 and other platforms and is done for performance reasons.
+        internal static unsafe void ZeroMemory(byte* dest, nuint len)
+        {
+            SpanHelpers.ClearWithoutReferences(ref *dest, len);
         }
 
         internal static unsafe void Memcpy(byte[] dest, int destIndex, byte* src, int srcIndex, int len)