-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Replace String.substr() with simpler functions where possible #82412
Conversation
914e412
to
02fbf8f
Compare
2545b46
to
92da4d3
Compare
I'll proof-read it now and leave comments to make reviewing easier. |
92da4d3
to
9330273
Compare
@@ -1330,7 +1330,7 @@ void Node::_generate_serial_child_name(const Node *p_child, StringName &name) co | |||
|
|||
// Assign the base name + separator to name if we have numbers preceded by a separator | |||
if (nums.length() > 0 && name_string.substr(name_last_index, nnsep.length()) == nnsep) { | |||
name_string = name_string.substr(0, name_last_index + nnsep.length()); | |||
name_string = name_string.left(name_last_index + nnsep.length()); |
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.
This is complex, but in a nutshell, I haven't determined if my change affects any behaviors. But if it does, then I'm 99% sure the old behavior would've also been problematic.
295b4bf
to
f3b5206
Compare
f3b5206
to
64b4d71
Compare
32878e4
to
8f37d8d
Compare
8f37d8d
to
ea873f7
Compare
ea873f7
to
bcf568a
Compare
I've self-reviewed this so extensively I don't think a second major review would be needed P: I'll finish this soon and comment on which changes I'm still skeptical about. |
I want to go about this differently. |
substr(0, len)
can be simplified toleft(len)
iflen >= 0
. In fact, this alternative is 10% faster.While this is mostly about code style, I expect the performance improvement to be subtle, but non-negligible. Since String also used
substr()
in a few places when it could useleft()
, this should optimize other String functions too, and those are used all over the codebase, too.And a couple of other code simplifications.