-
Notifications
You must be signed in to change notification settings - Fork 42
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
Address perf+correctness of StrLen and StrChr #480
Open
neon-sunset
wants to merge
8
commits into
ForNeVeR:main
Choose a base branch
from
neon-sunset:strlen-strchr-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9df5497
Address perf+correctness of StrLen and StrChr
neon-sunset 1dcd96d
Add missed null coverage
neon-sunset 7149d92
Fix incorrect impl., check if CI passes, temporarily drop NS2.0
neon-sunset 2ab0c15
Address SEGFAULT by implementing search manually and aligning the loa…
neon-sunset 2f2352e
Merge branch 'main' into strlen-strchr-fix
neon-sunset 23e2b61
Fix implementation
neon-sunset 20dd125
Extend test cases
neon-sunset cf488a7
Fix CI
neon-sunset File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Text; | ||
|
||
namespace Cesium.Runtime.Tests; | ||
|
||
public unsafe class StringFunctionTests | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add some Unicode tests, shall we? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will do |
||
{ | ||
[Theory] | ||
[InlineData("Hello\0", 5)] | ||
[InlineData("Goodbye\0", 7)] | ||
[InlineData("Hello\0Goodbye\0", 5)] | ||
[InlineData(" \0", 18)] | ||
public void StrLen(string input, int expected) | ||
{ | ||
// TODO: If you are rich enough to procure a 2-4+ GB RAM runner, | ||
// please update this test to exercise the path where the string | ||
// length exceeds int.MaxLength of bytes. | ||
var bytes = Encoding.UTF8.GetBytes(input); | ||
fixed (byte* str = bytes) | ||
{ | ||
var actual = StringFunctions.StrLen(str); | ||
|
||
Assert.Equal((nuint)expected, actual); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void StrLen_Null() | ||
{ | ||
var actual = StringFunctions.StrLen(null); | ||
|
||
Assert.Equal((nuint)0, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData("Hello\n", 5)] | ||
[InlineData("Goodbye\n", 7)] | ||
[InlineData("Hello\nGoodbye\n", 5)] | ||
[InlineData(" \n", 18)] | ||
public void StrChr(string input, int expectedOffset) | ||
{ | ||
var needle = '\n'; | ||
var bytes = Encoding.UTF8.GetBytes(input); | ||
fixed (byte* str = bytes) | ||
{ | ||
var ptr = StringFunctions.StrChr(str, '\n'); | ||
|
||
Assert.Equal((byte)needle, *ptr); | ||
Assert.Equal(expectedOffset, (int)(ptr - str)); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void StrChr_NotFound() | ||
{ | ||
var bytes = Encoding.UTF8.GetBytes("Hello\0"); | ||
fixed (byte* str = bytes) | ||
{ | ||
var actual = StringFunctions.StrChr(str, '\n'); | ||
|
||
Assert.True(actual is null); | ||
} | ||
} | ||
|
||
[Fact] | ||
public void StrChr_Null() | ||
{ | ||
var actual = StringFunctions.StrChr(null, '\0'); | ||
|
||
Assert.True(actual is null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
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.
After some thought, I still want us to support .NET Framework on Windows. Let's re-enable that here, and add a fallback implementation for .NET Standard.