-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Encapsulate and slightly optimize string contexts #14470
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
|
I don't really feel in a position to critique style, as I'm still new to contributing to CppNix, but my 2 cents is that this feels like endless layers of abstraction. How often are we planning on changing this type? Does it really need a name? |
|
We could give a shorter / less-qualified name. I would say we do want to change it with some frequency.
|
f029b14 to
fb677eb
Compare
|
OK @xokdvium, it's all yours now! |
fb677eb to
e6afa20
Compare
These steps are done (originally in order, but I squashed it as the end result is still pretty small, and the churn in the code comments was a bit annoying to keep straight). 1. Create proper struct type for string contexts on the heap This will make it easier to change this type in the future. 2. Make `Value::StringWithContext` iterable This make some for loops a lot more terse. 3. Encapsulate `Value::StringWithContext::Context::elems` It turns out the iterators we just exposed are sufficient. 4. Make `StringWithContext::Context` length-prefixed instead Rather than having a null pointer at the end, have a `size_t` at the beginning. This is the exact same size (note that null pointer is longer than null byte) and thus takes no more space! Also, see the new TODO on naming. The thing we already so-named is a builder type for string contexts, not the on-heap type. The `fromBuilder` static method reflects what the names ought to be too. Co-authored-by: Sergei Zimmerman <[email protected]>
e6afa20 to
318eea0
Compare
| /** | ||
| * @pre must be in sorted order | ||
| */ | ||
| value_type elems[]; |
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.
aww I did think my [/*size*/] was cute :)
(not a serious request to bring it back.)
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.
Yeah, I could do a more serious pass documenting our usage of flexible array members in the codebase. I wonder if it's an issue for portability when it comes to MSVC.
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.
look good! (approving @xokdvium's rebase / slight edits)
xokdvium
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.
Cleaned up slightly and used placement new. That hacky enumerate could easily be replaced with a std::ranges::transform
Motivation
These steps are done (originally in order, but I squashed it as the end result is still pretty small, and the churn in the code comments was a bit annoying to keep straight).
Create proper struct type for string contexts on the heap
This will make it easier to change this type in the future.
Make
Value::StringWithContextiterableThis make some for loops a lot more terse.
Encapsulate
Value::StringWithContext::Context::elemsIt turns out the iterators we just exposed are sufficient.
Make
StringWithContext::Contextlength-prefixed insteadRather than having a null pointer at the end, have a
size_tat the beginning. This is the exact same size (note that null pointer is longer than null byte) and thus takes no more space!Context
Also, see the new TODO on naming. The thing we already so-named is a builder type for string contexts, not the on-heap type. The
fromBuilderstatic method reflects what the names ought to be too.Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.