Skip to content

Commit

Permalink
Merge pull request #50809 from akien-mga/iterators-const-references
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jul 25, 2021
2 parents 2f221e5 + ac3322b commit ff0b5f8
Show file tree
Hide file tree
Showing 171 changed files with 649 additions and 650 deletions.
2 changes: 1 addition & 1 deletion core/config/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ bool Engine::has_singleton(const String &p_name) const {
}

void Engine::get_singletons(List<Singleton> *p_singletons) {
for (Singleton &E : singletons) {
for (const Singleton &E : singletons) {
p_singletons->push_back(E);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
if (E->key() != "") {
file->store_string("[" + E->key() + "]\n\n");
}
for (String &F : E->get()) {
for (const String &F : E->get()) {
String key = F;
if (E->key() != "") {
key = E->key() + "/" + key;
Expand Down Expand Up @@ -928,7 +928,7 @@ Vector<String> ProjectSettings::get_optimizer_presets() const {
ProjectSettings::get_singleton()->get_property_list(&pi);
Vector<String> names;

for (PropertyInfo &E : pi) {
for (const PropertyInfo &E : pi) {
if (!E.name.begins_with("optimizer_presets/")) {
continue;
}
Expand Down
20 changes: 10 additions & 10 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ 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 (String &E : exts) {
for (const String &E : exts) {
ret.push_back(E);
}

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

PackedStringArray ret;
for (String &E : deps) {
for (const String &E : deps) {
ret.push_back(E);
}

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

Expand Down Expand Up @@ -1822,7 +1822,7 @@ PackedStringArray _ClassDB::get_class_list() const {
PackedStringArray ret;
ret.resize(classes.size());
int idx = 0;
for (StringName &E : classes) {
for (const StringName &E : classes) {
ret.set(idx++, E);
}

Expand All @@ -1836,7 +1836,7 @@ PackedStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class)
PackedStringArray ret;
ret.resize(classes.size());
int idx = 0;
for (StringName &E : classes) {
for (const StringName &E : classes) {
ret.set(idx++, E);
}

Expand Down Expand Up @@ -1891,7 +1891,7 @@ 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 (MethodInfo &E : signals) {
for (const MethodInfo &E : signals) {
ret.push_back(E.operator Dictionary());
}

Expand All @@ -1902,7 +1902,7 @@ 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 (PropertyInfo &E : plist) {
for (const PropertyInfo &E : plist) {
ret.push_back(E.operator Dictionary());
}

Expand Down Expand Up @@ -1935,7 +1935,7 @@ 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 (MethodInfo &E : methods) {
for (const MethodInfo &E : methods) {
#ifdef DEBUG_METHODS_ENABLED
ret.push_back(E.operator Dictionary());
#else
Expand All @@ -1955,7 +1955,7 @@ PackedStringArray _ClassDB::get_integer_constant_list(const StringName &p_class,
PackedStringArray ret;
ret.resize(constants.size());
int idx = 0;
for (String &E : constants) {
for (const String &E : constants) {
ret.set(idx++, E);
}

Expand Down
2 changes: 1 addition & 1 deletion core/debugger/debugger_marshalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Array DebuggerMarshalls::ResourceUsage::serialize() {

Array arr;
arr.push_back(infos.size() * 4);
for (ResourceInfo &E : infos) {
for (const ResourceInfo &E : infos) {
arr.push_back(E.path);
arr.push_back(E.format);
arr.push_back(E.type);
Expand Down
2 changes: 1 addition & 1 deletion core/debugger/remote_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ void RemoteDebugger::_send_resource_usage() {
List<RS::TextureInfo> tinfo;
RS::get_singleton()->texture_debug_usage(&tinfo);

for (RS::TextureInfo &E : tinfo) {
for (const RS::TextureInfo &E : tinfo) {
DebuggerMarshalls::ResourceInfo info;
info.path = E.path;
info.vram = E.bytes;
Expand Down
24 changes: 12 additions & 12 deletions core/extension/extension_api_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
Dictionary d1;
d1["name"] = E->key();
Array values;
for (Pair<String, int> &F : E->get()) {
for (const Pair<String, int> &F : E->get()) {
Dictionary d2;
d2["name"] = F.first;
d2["value"] = F.second;
Expand All @@ -294,7 +294,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
List<StringName> utility_func_names;
Variant::get_utility_function_list(&utility_func_names);

for (StringName &name : utility_func_names) {
for (const StringName &name : utility_func_names) {
Dictionary func;
func["name"] = String(name);
if (Variant::has_utility_function_return_value(name)) {
Expand Down Expand Up @@ -362,7 +362,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {

List<StringName> member_names;
Variant::get_member_list(type, &member_names);
for (StringName &member_name : member_names) {
for (const StringName &member_name : member_names) {
Dictionary d2;
d2["name"] = String(member_name);
d2["type"] = Variant::get_type_name(Variant::get_member_type(type, member_name));
Expand All @@ -378,7 +378,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {

List<StringName> constant_names;
Variant::get_constants_for_type(type, &constant_names);
for (StringName &constant_name : constant_names) {
for (const StringName &constant_name : constant_names) {
Dictionary d2;
d2["name"] = String(constant_name);
Variant constant = Variant::get_constant_value(type, constant_name);
Expand Down Expand Up @@ -417,7 +417,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {

List<StringName> method_names;
Variant::get_builtin_method_list(type, &method_names);
for (StringName &method_name : method_names) {
for (const StringName &method_name : method_names) {
Dictionary d2;
d2["name"] = String(method_name);
if (Variant::has_builtin_method_return_value(type, method_name)) {
Expand Down Expand Up @@ -499,7 +499,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {

class_list.sort_custom<StringName::AlphCompare>();

for (StringName &class_name : class_list) {
for (const StringName &class_name : class_list) {
Dictionary d;
d["name"] = String(class_name);
d["is_refcounted"] = ClassDB::is_parent_class(class_name, "RefCounted");
Expand All @@ -520,7 +520,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
Array constants;
List<String> constant_list;
ClassDB::get_integer_constant_list(class_name, &constant_list, true);
for (String &F : constant_list) {
for (const String &F : constant_list) {
StringName enum_name = ClassDB::get_integer_constant_enum(class_name, F);
if (enum_name != StringName()) {
continue; //enums will be handled on their own
Expand All @@ -542,7 +542,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
Array enums;
List<StringName> enum_list;
ClassDB::get_enum_list(class_name, &enum_list, true);
for (StringName &F : enum_list) {
for (const StringName &F : enum_list) {
Dictionary d2;
d2["name"] = String(F);

Expand Down Expand Up @@ -570,7 +570,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
Array methods;
List<MethodInfo> method_list;
ClassDB::get_method_list(class_name, &method_list, true);
for (MethodInfo &F : method_list) {
for (const MethodInfo &F : method_list) {
StringName method_name = F.name;
if (F.flags & METHOD_FLAG_VIRTUAL) {
//virtual method
Expand Down Expand Up @@ -687,7 +687,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
Array signals;
List<MethodInfo> signal_list;
ClassDB::get_signal_list(class_name, &signal_list, true);
for (MethodInfo &F : signal_list) {
for (const MethodInfo &F : signal_list) {
StringName signal_name = F.name;
Dictionary d2;
d2["name"] = String(signal_name);
Expand Down Expand Up @@ -723,7 +723,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
Array properties;
List<PropertyInfo> property_list;
ClassDB::get_property_list(class_name, &property_list, true);
for (PropertyInfo &F : property_list) {
for (const PropertyInfo &F : property_list) {
if (F.usage & PROPERTY_USAGE_CATEGORY || F.usage & PROPERTY_USAGE_GROUP || F.usage & PROPERTY_USAGE_SUBGROUP) {
continue; //not real properties
}
Expand Down Expand Up @@ -766,7 +766,7 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
List<Engine::Singleton> singleton_list;
Engine::get_singleton()->get_singletons(&singleton_list);

for (Engine::Singleton &s : singleton_list) {
for (const Engine::Singleton &s : singleton_list) {
Dictionary d;
d["name"] = s.name;
if (s.class_name != StringName()) {
Expand Down
2 changes: 1 addition & 1 deletion core/extension/native_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ RES NativeExtensionResourceLoader::load(const String &p_path, const String &p_or

String library_path;

for (String &E : libraries) {
for (const String &E : libraries) {
Vector<String> tags = E.split(".");
bool all_tags_met = true;
for (int i = 0; i < tags.size(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void Input::get_argument_options(const StringName &p_function, int p_idx, List<S
List<PropertyInfo> pinfo;
ProjectSettings::get_singleton()->get_property_list(&pinfo);

for (PropertyInfo &pi : pinfo) {
for (const PropertyInfo &pi : pinfo) {
if (!pi.name.begins_with("input/")) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions core/input/input_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ String InputMap::_suggest_actions(const StringName &p_action) const {
float closest_similarity = 0.0;

// Find the most action with the most similar name.
for (StringName &action : actions) {
for (const StringName &action : actions) {
const float similarity = String(action).similarity(p_action);

if (similarity > closest_similarity) {
Expand Down Expand Up @@ -261,7 +261,7 @@ void InputMap::load_from_project_settings() {
List<PropertyInfo> pinfo;
ProjectSettings::get_singleton()->get_property_list(&pinfo);

for (PropertyInfo &pi : pinfo) {
for (const PropertyInfo &pi : pinfo) {
if (!pi.name.begins_with("input/")) {
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions core/io/dir_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static Error _erase_recursive(DirAccess *da) {

da->list_dir_end();

for (String &E : dirs) {
for (const String &E : dirs) {
Error err = da->change_dir(E);
if (err == OK) {
err = _erase_recursive(da);
Expand All @@ -114,7 +114,7 @@ static Error _erase_recursive(DirAccess *da) {
}
}

for (String &E : files) {
for (const String &E : files) {
Error err = da->remove(da->get_current_dir().plus_file(E));
if (err) {
return err;
Expand Down Expand Up @@ -362,7 +362,7 @@ Error DirAccess::_copy_dir(DirAccess *p_target_da, String p_to, int p_chmod_flag

list_dir_end();

for (String &rel_path : dirs) {
for (const String &rel_path : dirs) {
String target_dir = p_to + rel_path;
if (!p_target_da->dir_exists(target_dir)) {
Error err = p_target_da->make_dir(target_dir);
Expand Down
2 changes: 1 addition & 1 deletion core/io/image_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
bool ImageFormatLoader::recognize(const String &p_extension) const {
List<String> extensions;
get_recognized_extensions(&extensions);
for (String &E : extensions) {
for (const String &E : extensions) {
if (E.nocasecmp_to(p_extension) == 0) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion core/io/ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ Array IP::_get_local_addresses() const {
Array addresses;
List<IPAddress> ip_addresses;
get_local_addresses(&ip_addresses);
for (IPAddress &E : ip_addresses) {
for (const IPAddress &E : ip_addresses) {
addresses.push_back(E);
}

Expand Down
2 changes: 1 addition & 1 deletion core/io/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ String JSON::_stringify(const Variant &p_var, const String &p_indent, int p_cur_
}

bool first_key = true;
for (Variant &E : keys) {
for (const Variant &E : keys) {
if (first_key) {
first_key = false;
} else {
Expand Down
6 changes: 3 additions & 3 deletions core/io/marshalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
obj->get_property_list(&props);

int pc = 0;
for (PropertyInfo &E : props) {
for (const PropertyInfo &E : props) {
if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
Expand All @@ -1372,7 +1372,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo

r_len += 4;

for (PropertyInfo &E : props) {
for (const PropertyInfo &E : props) {
if (!(E.usage & PROPERTY_USAGE_STORAGE)) {
continue;
}
Expand Down Expand Up @@ -1418,7 +1418,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
List<Variant> keys;
d.get_key_list(&keys);

for (Variant &E : keys) {
for (const Variant &E : keys) {
/*
CharString utf8 = E->->utf8();
Expand Down
2 changes: 1 addition & 1 deletion core/io/multiplayer_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ void MultiplayerAPI::_del_peer(int p_id) {
// Some refactoring is needed to make this faster and do paths GC.
List<NodePath> keys;
path_send_cache.get_key_list(&keys);
for (NodePath &E : keys) {
for (const NodePath &E : keys) {
PathSentCache *psc = path_send_cache.getptr(E);
psc->confirmed_peers.erase(p_id);
}
Expand Down
4 changes: 2 additions & 2 deletions core/io/packed_data_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
d.get_key_list(&keys);
List<DictKey> sortk;

for (Variant &key : keys) {
for (const Variant &key : keys) {
DictKey dk;
dk.hash = key.hash();
dk.key = key;
Expand All @@ -278,7 +278,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
sortk.sort();

int idx = 0;
for (DictKey &E : sortk) {
for (const DictKey &E : sortk) {
encode_uint32(E.hash, &tmpdata.write[pos + 8 + idx * 12 + 0]);
uint32_t ofs = _pack(E.key, tmpdata, string_cache);
encode_uint32(ofs, &tmpdata.write[pos + 8 + idx * 12 + 4]);
Expand Down
Loading

0 comments on commit ff0b5f8

Please sign in to comment.