From 3317d79adf337c52306a8e55d7f65b547d1ae8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Foidl?= Date: Wed, 13 Mar 2019 21:33:07 +0100 Subject: [PATCH] Fewer instructions for check if either start or length != 0 --- src/System.Private.CoreLib/shared/System/Memory.cs | 2 +- .../shared/System/MemoryExtensions.Fast.cs | 4 ++-- src/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs | 2 +- src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs | 2 +- .../shared/System/Runtime/InteropServices/MemoryMarshal.cs | 2 +- src/System.Private.CoreLib/shared/System/Span.Fast.cs | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Memory.cs b/src/System.Private.CoreLib/shared/System/Memory.cs index ba31a6aeaeab..c97386bab168 100644 --- a/src/System.Private.CoreLib/shared/System/Memory.cs +++ b/src/System.Private.CoreLib/shared/System/Memory.cs @@ -90,7 +90,7 @@ public Memory(T[] array, int start, int length) { if (array == null) { - if (start != 0 || length != 0) + if ((start | length) != 0) ThrowHelper.ThrowArgumentOutOfRangeException(); this = default; return; // returns default diff --git a/src/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs b/src/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs index 1e1fd90e4468..1328fa4d4400 100644 --- a/src/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs +++ b/src/System.Private.CoreLib/shared/System/MemoryExtensions.Fast.cs @@ -502,7 +502,7 @@ public static ReadOnlySpan AsSpan(this string text, int start, int length) { if (text == null) { - if (start != 0 || length != 0) + if ((start | length) != 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); return default; } @@ -584,7 +584,7 @@ public static ReadOnlyMemory AsMemory(this string text, int start, int len { if (text == null) { - if (start != 0 || length != 0) + if ((start | length) != 0) ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); return default; } diff --git a/src/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs b/src/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs index 6c598430adbf..e29bd6db93f1 100644 --- a/src/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs +++ b/src/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs @@ -70,7 +70,7 @@ public ReadOnlyMemory(T[] array, int start, int length) { if (array == null) { - if (start != 0 || length != 0) + if ((start | length) != 0) ThrowHelper.ThrowArgumentOutOfRangeException(); this = default; return; // returns default diff --git a/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs b/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs index eb3fd1464d44..f5b9e2de7c5a 100644 --- a/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs +++ b/src/System.Private.CoreLib/shared/System/ReadOnlySpan.Fast.cs @@ -68,7 +68,7 @@ public ReadOnlySpan(T[] array, int start, int length) { if (array == null) { - if (start != 0 || length != 0) + if ((start | length) != 0) ThrowHelper.ThrowArgumentOutOfRangeException(); this = default; return; // returns default diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs index b1f550712246..87c70d420d0a 100644 --- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs +++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/MemoryMarshal.cs @@ -297,7 +297,7 @@ public static Memory CreateFromPinnedArray(T[] array, int start, int lengt { if (array == null) { - if (start != 0 || length != 0) + if ((start | length) != 0) ThrowHelper.ThrowArgumentOutOfRangeException(); return default; } diff --git a/src/System.Private.CoreLib/shared/System/Span.Fast.cs b/src/System.Private.CoreLib/shared/System/Span.Fast.cs index 66de4fe3d3f9..9f2c509bc759 100644 --- a/src/System.Private.CoreLib/shared/System/Span.Fast.cs +++ b/src/System.Private.CoreLib/shared/System/Span.Fast.cs @@ -72,7 +72,7 @@ public Span(T[] array, int start, int length) { if (array == null) { - if (start != 0 || length != 0) + if ((start | length) != 0) ThrowHelper.ThrowArgumentOutOfRangeException(); this = default; return; // returns default