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

Rewrite SpanHelpers.IndexOfNullByte/IndexOfNullCharacter to unmanaged pointers #81347

Merged
merged 3 commits into from
Jan 31, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jan 30, 2023

Addresses #81332

@ghost
Copy link

ghost commented Jan 30, 2023

Tagging subscribers to this area: @dotnet/area-system-memory
See info in area-owners.md if you want to be subscribed.

Issue Details

Addresses #81332

Author: EgorBo
Assignees: EgorBo
Labels:

area-System.Memory

Milestone: -


internal static unsafe int strlen(byte* ptr) => SpanHelpers.IndexOfNullByte(ref *ptr);
internal static unsafe int strlen(byte* ptr) => SpanHelpers.IndexOfNullByte(ptr);
Copy link
Member

@am11 am11 Jan 30, 2023

Choose a reason for hiding this comment

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

a nit: we can use SpanHelpers.IndexOfNullByte directly at call-sites and delete these wrappers to promote the usage of same API everywhere (CoreLib has total 21 call-sites of wcslen and strlen combined).

Copy link
Member Author

@EgorBo EgorBo Jan 30, 2023

Choose a reason for hiding this comment

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

a nit: we can use SpanHelpers.IndexOfNullByte directly at call-sites and delete these wrappers to promote the usage of same API everywhere (CoreLib has total 21 call-sites of wcslen and strlen combined).

It's a bit more complicated too delete it - e.g. VM relies on it for IL marshallers, mono seems too

Copy link
Member

@am11 am11 Jan 30, 2023

Choose a reason for hiding this comment

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

Ah corelib.h, forgot to check that. 😁
(they are used in ilmarshalers.cpp via METHOD__STRING__STRLEN and METHOD__STRING__WCSLEN macros)

Calls in C# code can use SpanHelpers directly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Calls in C# code can use SpanHelpers directly.

I wonder if in this case ILLink will trim strlen/the other one as unused and then VM will crash, so probably better to leave as is or rename completely?

Copy link
Member

Choose a reason for hiding this comment

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

For CoreCLR, ILLink keeps everything referenced by VM. I am not sure about Mono.

@EgorBo EgorBo merged commit 0043b6e into dotnet:main Jan 31, 2023
@EgorBo EgorBo deleted the cleanup-indexof-null branch January 31, 2023 19:07
@ghost ghost locked as resolved and limited conversation to collaborators Mar 3, 2023
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.

3 participants