-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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 iterator pattern instead of manually traverse List::Element *
#102354
base: master
Are you sure you want to change the base?
Conversation
740f08a
to
a669c2a
Compare
a669c2a
to
6601eb7
Compare
List::Element *
List::Element *
core/core_bind.cpp
Outdated
@@ -466,8 +466,8 @@ bool OS::is_restart_on_exit_set() const { | |||
Vector<String> OS::get_restart_on_exit_arguments() const { | |||
List<String> args = ::OS::get_singleton()->get_restart_on_exit_arguments(); | |||
Vector<String> args_vector; | |||
for (List<String>::Element *E = args.front(); E; E = E->next()) { | |||
args_vector.push_back(E->get()); | |||
for (const String &E : args) { |
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.
We shouldn't reuse the same variable name here. Before, E
was short for List<String>::Element
, but now, it means arg
.
for (const String &E : args) { | |
for (const String &arg : args) { |
This comment is good for all the replacements in the PR.
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.
Or whatever is applicable in that context; if nothing feels appropriate, something generic like item
or element
works just as well
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.
Thanks for the naming suggestion. I'm not very familiar with these code, so I prefer to use the original names to avoid issues like name conflicts. If you have a better name in mind, please feel free to suggest it.
b910fb8
to
306a3c4
Compare
Co-authored-by: Adam Scott <[email protected]>
306a3c4
to
7b486a0
Compare
This is mostly a style change.
for (List<>::Element *E = list.front(); E; E = E->next())
is lengthy and hard to read,for (const Type &E : list)
make it clear that we are doing a one-way scan and not mutating the container or elements.An additional benefit is that we have removed the type name of
List
from the loop, making it possible to replace the container type in the future. In the previous pattern, we would have to modify thefor
loop if we wanted to replaceList
withVector
orLocalVector
.