Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Fewer instructions for check if either start or length != 0 #23239

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/System.Private.CoreLib/shared/System/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public static ReadOnlySpan<char> 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;
}
Expand Down Expand Up @@ -584,7 +584,7 @@ public static ReadOnlyMemory<char> 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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Private.CoreLib/shared/System/ReadOnlyMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public static Memory<T> CreateFromPinnedArray<T>(T[] array, int start, int lengt
{
if (array == null)
{
if (start != 0 || length != 0)
if ((start | length) != 0)
ThrowHelper.ThrowArgumentOutOfRangeException();
return default;
}
Expand Down
2 changes: 1 addition & 1 deletion src/System.Private.CoreLib/shared/System/Span.Fast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down