-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
Add move constructor and move assignment to CowData
, String
, Char16String
, CharString
, and Vector
.
#100239
Add move constructor and move assignment to CowData
, String
, Char16String
, CharString
, and Vector
.
#100239
Conversation
311b953
to
ee8bb5e
Compare
CowData
, String
, Char16String
, CharString
and Vector
.CowData
, String
, Char16String
, CharString
, Vector
and Variant
.
ee8bb5e
to
5cbf393
Compare
CowData
, String
, Char16String
, CharString
, Vector
and Variant
.CowData
, String
, Char16String
, CharString
, and Vector
.
I removed the |
5cbf393
to
4cb8e65
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.
On a performance standpoint, I think this is good as it will avoid unecessary copies. But because of having to use std::move
, it brings some STL headers, which is against the Godot Guidelines, so this needs to be discussed by maintainers, I would think. Move semantic is weird this way as annotation is in the language : the &&
, but triggering a move on a named variable isn't std::move
being in the library. Maybe you could propose a godot version of move ?
Notably,
I guess that would be possible, but is it really that important to avoid include |
To be honest I don't know. The only |
We can use things from std::, it is fine. We use std::thread already. The rule only applies to STL containers and such. Using std::move in this context is 100% fine. |
All looks really straightforwardly correct, I'll run some tests later but I have no style or technical comments. |
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.
If std::move is fine, then this is good. It has some huge speed up potential.
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, Variant
is a fickle and hacky beast, no need to worry about it now
Integrating move constructors/assignment is honestly overdue; I think they're already being utilized in godot-cpp
to a limited extent. This implementation makes sense and looks good, nice work!
Just for background. At the contributor meeting this past October we had a long discussion about including certain modern C++ features. We talked about move specifically in detail and the consensus was:
I think this PR is in line with our discussion. HP and I also discussed a few other places in core that would benefit from using move. That being said, we need to be careful about where we use it an how. We shouldn't just be adding move wherever we see a place that it can fit, we should check everything with a profiler and ensure we are actually having an impact and not needlessly making our code difficult to read |
…ring, CharString and Vector.
4cb8e65
to
57073ba
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.
Some smoke tests suggest no problems.
Thanks! |
This will allow the compiler to optimize transfer of data better. Previously, a transfer would necessitate incrementing and decrementing the
refcount
unnecessarily. Now, it is possible to simply transfer the data by swapping pointer ownership.The new constructor and assignment operators are selected automatically, instead of the copy versions, for compatible callers, without any explicit adjustments required.
This should grease the gears and make some parts of Godot faster and / or smaller and / or compile faster by a nebulous small factor.