Skip to content

Use spans in low level lexer char array handling code #79232

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 4 commits into from
Jul 2, 2025

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Jul 2, 2025

Found while doing work in simplifying the lexer/sliding-text-window code. As these are all about efficiently workign with contiguous segments of characters, this fell out as a nice simplification.

Note that a bunch of this code was already span-ified previously. This just pushes that spanification higher to some internal component boundary points.

char[] textBuffer,
int keyStart,
int keyLength,
ReadOnlySpan<char> textBuffer,
Copy link
Member Author

Choose a reason for hiding this comment

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

much cleaner to just pass spans all the way through. in the bowels that's all we were using the array+start+length for anyways.


return hashCode;
}
=> GetFNVHashCode(text.AsSpan(start, length));
Copy link
Member Author

Choose a reason for hiding this comment

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

we already have the overload that works on a ROS. just defer to that.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review July 2, 2025 18:30
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 2, 2025 18:30
@CyrusNajmabadi
Copy link
Member Author

@dotnet/roslyn-compiler this is ready for review.

{
var span = chars.AsSpan(start, len);
Copy link
Member Author

Choose a reason for hiding this comment

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

note that these layers were also often using spans. Now they don't use spans partially for some op, and array+start+length for others. They use spans consistently through teh entire path.

Copy link
Member

@RikkiGibson RikkiGibson left a comment

Choose a reason for hiding this comment

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

looks like some tests also need updating

@CyrusNajmabadi
Copy link
Member Author

looks like some tests also need updating

Thanks. Fixed @RikkiGibson

@CyrusNajmabadi
Copy link
Member Author

@chsienki ptal.

@CyrusNajmabadi CyrusNajmabadi requested a review from chsienki July 2, 2025 19:38
@CyrusNajmabadi CyrusNajmabadi enabled auto-merge (squash) July 2, 2025 19:45
@CyrusNajmabadi CyrusNajmabadi merged commit fb38d6b into dotnet:main Jul 2, 2025
23 of 24 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the useSpan branch July 2, 2025 20:10
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 2, 2025
333fred added a commit that referenced this pull request Jul 3, 2025
RikkiGibson pushed a commit that referenced this pull request Jul 3, 2025
CyrusNajmabadi added a commit to CyrusNajmabadi/roslyn that referenced this pull request Jul 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants