Skip to content
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

Merged
merged 3 commits into from
May 3, 2020

Conversation

benaadams
Copy link
Member

@benaadams benaadams commented May 3, 2020

@benaadams benaadams changed the title SpanHelpers.Byte use nuint rather than byte* and IntPtr SpanHelpers use nuint rather than byte* and IntPtr May 3, 2020
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Copy link
Member

@GrabYourPitchforks GrabYourPitchforks left a 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)
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed lengths to nuints

Unsafe.As<T, byte>(ref value),
count);
(uint)count);
Copy link
Member

@jkotas jkotas May 3, 2020

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted, can follow up

@benaadams
Copy link
Member Author

Can change the casts for now to double casts (nuint) => (nuint)(uint) then look at clean up later

@jkotas jkotas merged commit 11a8fa5 into dotnet:master May 3, 2020
@GrabYourPitchforks
Copy link
Member

Thanks Ben! :)

@benaadams benaadams deleted the nuint branch May 4, 2020 00:06
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants