-
Notifications
You must be signed in to change notification settings - Fork 596
Expression#GetReference(): ref, not copy, index if possible #9579
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
base: master
Are you sure you want to change the base?
Conversation
julianbrost
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.
Please update the PR description to explain what it's doing and why.
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.
So from more looking at the code, I got some clues, but I still don't get the full picture. In my understanding, a good PR description should give me this picture, I shouldn't have to reverse-engineer it from the code change.
Your new RefIndex type is somewhat like std::variant<const String&, String>, sometimes capturing a string by reference, sometimes by value. But why is this needed? What are the situations where it can be referenced and what are those where it can't? Also, what is the purpose of the index/vindex parameters/variables that this is used for? The non-existing documentation for it doesn't help, but as you has looked into this, please share your knowledge.
|
E.g. look at this:
The current master copies the index unconditionally. #9579 is smarter. Whenever an index can be returned "by ref", that's done. The interesting (for you) changes are in |
|
So in other words: For assignments, a reference to the storage location is needed. This reference is represented by the surrounding container ( Now consider the following two assignments:
In both examples, the reference for the left-hand side will be a reference to Is that correct so far? |
Tbh I've already played with the thought of (referenceably) caching full-constexpr never-mutated computation results. But that's another story... |
|
Which is such a common operation for compilers, it even has a name: https://en.wikipedia.org/wiki/Constant_folding But you can still do |
Before/after,
|

to avoid malloc().
Expression#GetReference()"returns" the parent object and the index (key) of a (not necessarily yet set) field.Now it tries to return the index by ref not to have to copy it.