This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Intrinsicify SpanHelpers.IndexOf(char) #22505
Intrinsicify SpanHelpers.IndexOf(char) #22505
Changes from all commits
d3ad966
ee6bdf0
09aecea
13402ac
d18cabf
02ce520
5095e6c
9eefea4
4f97783
24c7ef7
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I think the comment could be clarified to explain the logic here.
Basically, under optimal conditions we are not 32-byte aligned and are instead 16-byte aligned. In the non-optimal case, we could have any alignment, but we definitely have at least 16-bytes available to read, so we shouldn't fault.
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.
However, I'm not sure what (in the non-optimal case) prevents an AV for searches with no upper bound (String.wcslen)....
That is, if someone creates a span over unpinned data and with
length: int.MaxValue
and then they callIndexOf('\0')
, the length could be less than 16, and it could be relocated to just before the end of a page, which could then fault when we do theLoadVector128
below, right?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.
String.wcslen(char* ptr)
is over pointer data so the input is fixed data and the GC can't relocate it. No guarantees are offered for unfixed data and if you are creating a Span that is larger than data you own you're already in trouble; if there is no null terminator then it will rightfully fault.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.
We should likely have a comment explicitly calling that out then. Specifically that this assumes that the length is either correct or that the data is pinned and that you may AV otherwise.
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.
Improved comment