-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Core: Integrate Ref instantiate
where possible
#92986
Core: Integrate Ref instantiate
where possible
#92986
Conversation
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 good and improves readability quite substantially
e2fd2ce
to
a3e7aa0
Compare
a3e7aa0
to
076fa63
Compare
I'm curious, we seem to flip between memnew and instantiate. Which one do we pick for reviews? |
Ideally, we'd want to use instantiate over memnew where possible. As mentioned in the OP, the only places where that isn't feasible is when it's the same line // old
Ref<SomeType> some_value = Ref<SomeType>(memnew(SomeType()));
// new
Ref<SomeType> some_value = Ref<SomeType>::construct(); Initially I wanted to tackle that in a separate PR, but if desired I could integrate it here instead |
076fa63
to
789ae99
Compare
…Alternatively, if keeping within the initial scope of the PR is desired, there's this: // old
Ref<SomeType> some_value = Ref<SomeType>(memnew(SomeType()));
// new
Ref<SomeType> some_value;
some_value.instantiate(); I'd say this is still more readable than using However, this wouldn't remove the need for a static constructor. To demonstrate, here's a scenario where // old
some_function(Ref<SomeType>(memnew(SomeType)));
// new (static)
some_function(Ref<SomeType>::construct());
// new (local)
Ref<SomeType> some_value;
some_value.instantiate();
some_function(some_value); With all this in mind, I'll probably leave this concept alone for now. Maaaybe I'll sweep for cases that aren't reliant on one-liners, but I'd prefer to keep this PR as simple as possible |
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.
Everything seems alright!
I'm all for the new behavior. I'm already coding in that way and it does what it says.
I actually don't agree. I don't think passing a new instance of void my_func() {
...
{
// The ideal code would scope the ref to deference it ASAP.
Ref<SomeType> some_value;
some_value.instantiate();
some_function(some_value);
}
...
} Or, we could always make it so that void my_func() {
...
{
Ref<SomeType> some_value;
some_function(some_value.instantiate());
}
...
} |
789ae99
to
925b690
Compare
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 good.
Followup to #88183, which expanded
Ref<T>::instantiate()
to accept constructor arguments. This PR is focused on converting existing Ref constructors to the shorthand syntax where applicable. Does not convert every instance, as some constructors happen on the same line a Ref is declared; converting these would require a static method, and is more suitable as a separate PR.