-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Use const references where possible for List range iterators #50809
Use const references where possible for List range iterators #50809
Conversation
9783cdb
to
5051c57
Compare
for (Property &F : rd.properties) { | ||
Property &p = F; | ||
for (const Property &p : rd.properties) { |
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.
Changed this as it seemed redundant.
@@ -8542,7 +8542,7 @@ void RenderingDeviceVulkan::_free_rids(T &p_owner, const char *p_type) { | |||
} else { | |||
WARN_PRINT(vformat("%d RIDs of type \"%s\" were leaked.", owned.size(), p_type)); | |||
} | |||
for (RID E : owned) { | |||
for (const RID &E : owned) { |
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.
Turned all for (RID foo : bar)
into for (const RID &foo : bar)
.
I didn't double check the implications but @reduz also seemed to think it's fine.
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, const reference is better here.
for (Object::Connection &F : cl) { | ||
Object::Connection &c = F; | ||
for (const Object::Connection &c : cl) { |
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.
Simplified.
@@ -1431,7 +1431,7 @@ class GDScriptParser { | |||
void push_line(const String &p_line = String()); | |||
void push_text(const String &p_text); | |||
|
|||
void print_annotation(AnnotationNode *p_annotation); | |||
void print_annotation(const AnnotationNode *p_annotation); |
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.
I made this change to allow compiling the other changes iterating with const AnnotationNode *E
, and since the method doesn't seem to modify the node.
But I see now it makes it inconsistent with other print_*
methods, I could change it back if needed @vnen.
for (const lsp::DocumentSymbol *&E : list) { | ||
if (const lsp::DocumentSymbol *s = E) { | ||
contents.push_back(s->render().value); | ||
} | ||
for (const lsp::DocumentSymbol *s : list) { | ||
contents.push_back(s->render().value); |
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.
I think the code should be equivalent?
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.
I don't think those are equivalent. The =
operator returns the value of the newly assigned variable. So the original code is assigning and checking for nullptr
at the same time. So with the new code we may be accessing an null pointer.
Some stuff I noticed while working on this:
|
5051c57
to
467ec69
Compare
Updated to leave the |
467ec69
to
48b96fd
Compare
48b96fd
to
ac3322b
Compare
Follow-up to #50511.