-
-
Notifications
You must be signed in to change notification settings - Fork 884
Handle hex parsing in Color with format support #2964
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
cc2da89
Handle hex parsing in Color with format support
JimBobSquarePants 6e7b7ac
Rewrite to remove allocations
JimBobSquarePants 64e5047
Fix formatting
JimBobSquarePants 06d30b2
Create zero-allocation version
JimBobSquarePants 8aad064
Use primed OS independent LFS caching
JimBobSquarePants 8fb934a
Merge branch 'main' into js/color-hex-normalize
JimBobSquarePants 2187c92
Use a normalized cache key so Windows uses it.
JimBobSquarePants cd03d18
Merge branch 'js/color-hex-normalize' of https://github.com/SixLaborsโฆ
JimBobSquarePants 1fc5c6e
Fix LFS caching
JimBobSquarePants 991d838
Remove bad task
JimBobSquarePants 1440945
Try to get Windows to use the cache
JimBobSquarePants 96399e7
Try again.
JimBobSquarePants 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 hidden or 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.
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.
Similar to #2963 (comment), I'd use
string.Create
here (note: due the collection expression, C# will emit a inline here and no allocation happens, but it's unneded copying around the value).Uh oh!
There was an error while loading. Please reload this page.
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.
@gfoidl I wrote the faster one:
We parse to string, and then parse string to uint. In fact, we can achieve zero alloc.
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.
๐๐ป
Instead of the
if (c >= 'a' && c <= 'f')
you can use pattern matching (is
), as Roslyn will emit optimized tests (at least in a future version, but some of them are already enabled).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.
Dammit you nerd sniped me!! ๐คฃ
I've updated the code to use a zero-allocation implementation for both RGBA and ARGB layout.
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.
@JimBobSquarePants The code I shown is the zero-allocation implementation. See my benchmark for the code I shown, and you can find my benchmark code in https://github.com/lindexi/lindexi_gd/blob/8422ee2ff82386e57eeb8bb43735a7ef3121782f/Workbench/RenalwhuchewelneHukawine/ColorParserBenchmark.cs
The origin code in ImageSharp should alloc some memory.
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 you may have misunderstood what I said. The code in this PR is now zero allocation for both RGBA and ARGB scenarios.