-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SpanHelpers use nuint rather than byte* and IntPtr #35765
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor suggestions, but don't hold up this PR for them :)
@@ -105,21 +105,21 @@ public static int LastIndexOfAny(ref byte searchSpace, int searchSpaceLength, re | |||
|
|||
// Adapted from IndexOf(...) | |||
[MethodImpl(MethodImplOptions.AggressiveOptimization)] | |||
public static unsafe bool Contains(ref byte searchSpace, byte value, int length) | |||
public static bool Contains(ref byte searchSpace, byte value, int length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are lots of casts ((nuint)length
) in this method. (And remember, in 64-bit procs this is a signed extension.) Seems like ideally the 'length' parameter would be taken as a nuint
instead of an int
to avoid all of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe change the Asserts from
Debug.Assert(searchSpaceLength >= 0);
Debug.Assert(valueLength >= 0);
to
Debug.Assert((nint)searchSpaceLength >= 0);
Debug.Assert((nint)valueLength >= 0);
to make it still valid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed lengths to nuint
s
src/libraries/System.Private.CoreLib/src/System/SpanHelpers.Byte.cs
Outdated
Show resolved
Hide resolved
Unsafe.As<T, byte>(ref value), | ||
count); | ||
(uint)count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is moving more code to aggressive inlined callsite that is not an improvement. I think it was better as int
before this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or leave this part of the change to separate PR where we can look at the impact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted, can follow up
Can change the casts for now to double casts |
Thanks Ben! :) |
/cc @GrabYourPitchforks @jkotas