Skip to content

Commit

Permalink
Use C++ iterators for Lists in many situations
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfranke committed Jul 23, 2021
1 parent b918c4c commit 4e6efd1
Show file tree
Hide file tree
Showing 218 changed files with 2,755 additions and 3,004 deletions.
4 changes: 2 additions & 2 deletions core/config/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ bool Engine::has_singleton(const String &p_name) const {
}

void Engine::get_singletons(List<Singleton> *p_singletons) {
for (List<Singleton>::Element *E = singletons.front(); E; E = E->next()) {
p_singletons->push_back(E->get());
for (Singleton &E : singletons) {
p_singletons->push_back(E);
}
}

Expand Down
19 changes: 8 additions & 11 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
int count = 0;

for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
count++;
}
count += E->get().size();
}

if (p_custom_features != String()) {
Expand Down Expand Up @@ -734,8 +732,7 @@ Error ProjectSettings::_save_settings_binary(const String &p_file, const Map<Str
}

for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
String key = F->get();
for (String &key : E->get()) {
if (E->key() != "") {
key = E->key() + "/" + key;
}
Expand Down Expand Up @@ -803,8 +800,8 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
if (E->key() != "") {
file->store_string("[" + E->key() + "]\n\n");
}
for (List<String>::Element *F = E->get().front(); F; F = F->next()) {
String key = F->get();
for (String &F : E->get()) {
String key = F;
if (E->key() != "") {
key = E->key() + "/" + key;
}
Expand All @@ -817,7 +814,7 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin

String vstr;
VariantWriter::write_to_string(value, vstr);
file->store_string(F->get().property_name_encode() + "=" + vstr + "\n");
file->store_string(F.property_name_encode() + "=" + vstr + "\n");
}
}

Expand Down Expand Up @@ -931,11 +928,11 @@ Vector<String> ProjectSettings::get_optimizer_presets() const {
ProjectSettings::get_singleton()->get_property_list(&pi);
Vector<String> names;

for (List<PropertyInfo>::Element *E = pi.front(); E; E = E->next()) {
if (!E->get().name.begins_with("optimizer_presets/")) {
for (PropertyInfo &E : pi) {
if (!E.name.begins_with("optimizer_presets/")) {
continue;
}
names.push_back(E->get().name.get_slicec('/', 1));
names.push_back(E.name.get_slicec('/', 1));
}

names.sort();
Expand Down
62 changes: 30 additions & 32 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ Vector<String> _ResourceLoader::get_recognized_extensions_for_type(const String
List<String> exts;
ResourceLoader::get_recognized_extensions_for_type(p_type, &exts);
Vector<String> ret;
for (List<String>::Element *E = exts.front(); E; E = E->next()) {
ret.push_back(E->get());
for (String &E : exts) {
ret.push_back(E);
}

return ret;
Expand All @@ -91,8 +91,8 @@ PackedStringArray _ResourceLoader::get_dependencies(const String &p_path) {
ResourceLoader::get_dependencies(p_path, &deps);

PackedStringArray ret;
for (List<String>::Element *E = deps.front(); E; E = E->next()) {
ret.push_back(E->get());
for (String &E : deps) {
ret.push_back(E);
}

return ret;
Expand Down Expand Up @@ -141,8 +141,8 @@ Vector<String> _ResourceSaver::get_recognized_extensions(const RES &p_resource)
List<String> exts;
ResourceSaver::get_recognized_extensions(p_resource, &exts);
Vector<String> ret;
for (List<String>::Element *E = exts.front(); E; E = E->next()) {
ret.push_back(E->get());
for (String &E : exts) {
ret.push_back(E);
}
return ret;
}
Expand Down Expand Up @@ -268,8 +268,8 @@ String _OS::get_name() const {
Vector<String> _OS::get_cmdline_args() {
List<String> cmdline = OS::get_singleton()->get_cmdline_args();
Vector<String> cmdlinev;
for (List<String>::Element *E = cmdline.front(); E; E = E->next()) {
cmdlinev.push_back(E->get());
for (String &E : cmdline) {
cmdlinev.push_back(E);
}

return cmdlinev;
Expand Down Expand Up @@ -355,29 +355,29 @@ void _OS::print_all_textures_by_size() {
List<Ref<Resource>> rsrc;
ResourceCache::get_cached_resources(&rsrc);

for (List<Ref<Resource>>::Element *E = rsrc.front(); E; E = E->next()) {
if (!E->get()->is_class("ImageTexture")) {
for (Ref<Resource> E : rsrc) {
if (!E->is_class("ImageTexture")) {
continue;
}

Size2 size = E->get()->call("get_size");
int fmt = E->get()->call("get_format");
Size2 size = E->call("get_size");
int fmt = E->call("get_format");

_OSCoreBindImg img;
img.size = size;
img.fmt = fmt;
img.path = E->get()->get_path();
img.path = E->get_path();
img.vram = Image::get_image_data_size(img.size.width, img.size.height, Image::Format(img.fmt));
img.id = E->get()->get_instance_id();
img.id = E->get_instance_id();
total += img.vram;
imgs.push_back(img);
}
}

imgs.sort();

for (List<_OSCoreBindImg>::Element *E = imgs.front(); E; E = E->next()) {
total -= E->get().vram;
for (_OSCoreBindImg &E : imgs) {
total -= E.vram;
}
}

Expand All @@ -387,9 +387,7 @@ void _OS::print_resources_by_type(const Vector<String> &p_types) {
List<Ref<Resource>> resources;
ResourceCache::get_cached_resources(&resources);

for (List<Ref<Resource>>::Element *E = resources.front(); E; E = E->next()) {
Ref<Resource> r = E->get();

for (Ref<Resource> r : resources) {
bool found = false;

for (int i = 0; i < p_types.size(); i++) {
Expand Down Expand Up @@ -1824,8 +1822,8 @@ PackedStringArray _ClassDB::get_class_list() const {
PackedStringArray ret;
ret.resize(classes.size());
int idx = 0;
for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
ret.set(idx++, E->get());
for (StringName &E : classes) {
ret.set(idx++, E);
}

return ret;
Expand All @@ -1838,8 +1836,8 @@ PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class)
PackedStringArray ret;
ret.resize(classes.size());
int idx = 0;
for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
ret.set(idx++, E->get());
for (StringName &E : classes) {
ret.set(idx++, E);
}

return ret;
Expand Down Expand Up @@ -1893,8 +1891,8 @@ Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const
ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
Array ret;

for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
ret.push_back(E->get().operator Dictionary());
for (MethodInfo &E : signals) {
ret.push_back(E.operator Dictionary());
}

return ret;
Expand All @@ -1904,8 +1902,8 @@ Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) con
List<PropertyInfo> plist;
ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
Array ret;
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
ret.push_back(E->get().operator Dictionary());
for (PropertyInfo &E : plist) {
ret.push_back(E.operator Dictionary());
}

return ret;
Expand Down Expand Up @@ -1937,12 +1935,12 @@ Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const
ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
Array ret;

for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
for (MethodInfo &E : methods) {
#ifdef DEBUG_METHODS_ENABLED
ret.push_back(E->get().operator Dictionary());
ret.push_back(E.operator Dictionary());
#else
Dictionary dict;
dict["name"] = E->get().name;
dict["name"] = E.name;
ret.push_back(dict);
#endif
}
Expand All @@ -1957,8 +1955,8 @@ PackedStringArray _ClassDB::get_integer_constant_list(const StringName &p_class,
PackedStringArray ret;
ret.resize(constants.size());
int idx = 0;
for (List<String>::Element *E = constants.front(); E; E = E->next()) {
ret.set(idx++, E->get());
for (String &E : constants) {
ret.set(idx++, E);
}

return ret;
Expand Down
10 changes: 5 additions & 5 deletions core/debugger/debugger_marshalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ Array DebuggerMarshalls::ResourceUsage::serialize() {

Array arr;
arr.push_back(infos.size() * 4);
for (List<ResourceInfo>::Element *E = infos.front(); E; E = E->next()) {
arr.push_back(E->get().path);
arr.push_back(E->get().format);
arr.push_back(E->get().type);
arr.push_back(E->get().vram);
for (ResourceInfo &E : infos) {
arr.push_back(E.path);
arr.push_back(E.format);
arr.push_back(E.type);
arr.push_back(E.vram);
}
return arr;
}
Expand Down
6 changes: 3 additions & 3 deletions core/debugger/local_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@ void LocalDebugger::print_variables(const List<String> &names, const List<Varian
String value;
Vector<String> value_lines;
const List<Variant>::Element *V = values.front();
for (const List<String>::Element *E = names.front(); E; E = E->next()) {
for (const String &E : names) {
value = String(V->get());

if (variable_prefix.is_empty()) {
print_line(E->get() + ": " + String(V->get()));
print_line(E + ": " + String(V->get()));
} else {
print_line(E->get() + ":");
print_line(E + ":");
value_lines = value.split("\n");
for (int i = 0; i < value_lines.size(); ++i) {
print_line(variable_prefix + value_lines[i]);
Expand Down
14 changes: 7 additions & 7 deletions core/debugger/remote_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,16 @@ void RemoteDebugger::_send_resource_usage() {
List<RS::TextureInfo> tinfo;
RS::get_singleton()->texture_debug_usage(&tinfo);

for (List<RS::TextureInfo>::Element *E = tinfo.front(); E; E = E->next()) {
for (RS::TextureInfo &E : tinfo) {
DebuggerMarshalls::ResourceInfo info;
info.path = E->get().path;
info.vram = E->get().bytes;
info.id = E->get().texture;
info.path = E.path;
info.vram = E.bytes;
info.id = E.texture;
info.type = "Texture";
if (E->get().depth == 0) {
info.format = itos(E->get().width) + "x" + itos(E->get().height) + " " + Image::get_format_name(E->get().format);
if (E.depth == 0) {
info.format = itos(E.width) + "x" + itos(E.height) + " " + Image::get_format_name(E.format);
} else {
info.format = itos(E->get().width) + "x" + itos(E->get().height) + "x" + itos(E->get().depth) + " " + Image::get_format_name(E->get().format);
info.format = itos(E.width) + "x" + itos(E.height) + "x" + itos(E.depth) + " " + Image::get_format_name(E.format);
}
usage.infos.push_back(info);
}
Expand Down
Loading

1 comment on commit 4e6efd1

@alaniv
Copy link

@alaniv alaniv commented on 4e6efd1 Jul 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this commit a violation to the guidelines?

https://docs.godotengine.org/en/latest/community/contributing/cpp_usage_guidelines.html

Don't use the for range loop syntax (for (String string : some_array)). Use traditional for loops instead as they're more explicit.

Please sign in to comment.