-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Cheap cloneable LineIndex #3896
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
Conversation
|
Current dependencies on/for this PR: This comment was auto-generated by Graphite. |
d9a3769 to
ab2d3c2
Compare
d25c8d4 to
d6d4ed8
Compare
ab2d3c2 to
6d2ccf7
Compare
PR Check ResultsEcosystem✅ ecosystem check detected no changes. BenchmarkLinuxWindows |
8ce729d to
b0f2c79
Compare
charliermarsh
left a comment
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.
Looks great.
| /// Internally this is represented as a [`NonZeroUsize`], this enables some | ||
| /// memory optimizations | ||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
| pub struct OneIndexed(NonZeroUsize); |
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've never used NonZeroUSize so I'll just ask: why do we need OneIndexed at all? Can we not use that type directly?
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 could. But I prefer semantic wrapper types because they communicate intent and allow us to limit the API, add helper methods that are only meaningful in this context (e.g. to_zero_indexed) or use method names that are more adequate in this context.
The use of wrapper types further allows us to replace the internal representation if we want (e.g. use a NonZeroU32) or to search for all usages of that concept (we may want to use NonZeroUsize in other places that are entirely unrelated).
f5193e6 to
2ba3c0d
Compare
b0f2c79 to
fb178f3
Compare

This PR extracts the
Indextype fromLocator, changes it to use anArcinternally to make it cheaply cloneable, and makes it public.The motivation for this change is that I want to output an advice with the recommended fix in the
textandgroupedemitter if--show-sourcesis true. Doing so requires access to the source code and theLineIndexto apply the edits.I used this chance to change the
LocatorandLineIndexto returnTextSizerather thanusizes for byte offsets.