Skip to content

Commit

Permalink
Merge pull request #51409 from LightningAA/use-map-iterators
Browse files Browse the repository at this point in the history
Use range iterators for `Map` in most cases
  • Loading branch information
akien-mga authored Sep 30, 2021
2 parents 3e1b630 + c63b185 commit 77721b3
Show file tree
Hide file tree
Showing 154 changed files with 1,897 additions and 1,900 deletions.
36 changes: 18 additions & 18 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,15 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {

Set<_VCSort> vclist;

for (Map<StringName, VariantContainer>::Element *E = props.front(); E; E = E->next()) {
const VariantContainer *v = &E->get();
for (const KeyValue<StringName, VariantContainer> &E : props) {
const VariantContainer *v = &E.value;

if (v->hide_from_editor) {
continue;
}

_VCSort vc;
vc.name = E->key();
vc.name = E.key;
vc.order = v->order;
vc.type = v->variant.get_type();
if (vc.name.begins_with("input/") || vc.name.begins_with("import/") || vc.name.begins_with("export/") || vc.name.begins_with("/remap") || vc.name.begins_with("/locale") || vc.name.begins_with("/autoload")) {
Expand Down Expand Up @@ -318,14 +318,14 @@ bool ProjectSettings::_load_resource_pack(const String &p_pack, bool p_replace_f
void ProjectSettings::_convert_to_last_version(int p_from_version) {
if (p_from_version <= 3) {
// Converts the actions from array to dictionary (array of events to dictionary with deadzone + events)
for (Map<StringName, ProjectSettings::VariantContainer>::Element *E = props.front(); E; E = E->next()) {
Variant value = E->get().variant;
if (String(E->key()).begins_with("input/") && value.get_type() == Variant::ARRAY) {
for (KeyValue<StringName, ProjectSettings::VariantContainer> &E : props) {
Variant value = E.value.variant;
if (String(E.key).begins_with("input/") && value.get_type() == Variant::ARRAY) {
Array array = value;
Dictionary action;
action["deadzone"] = Variant(0.5f);
action["events"] = array;
E->get().variant = action;
E.value.variant = action;
}
}
}
Expand Down Expand Up @@ -695,8 +695,8 @@ 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()) {
count += E->get().size();
for (const KeyValue<String, List<String>> &E : props) {
count += E.value.size();
}

if (p_custom_features != String()) {
Expand Down Expand Up @@ -788,7 +788,7 @@ Error ProjectSettings::_save_settings_text(const String &p_file, const Map<Strin
}
file->store_string("\n");

for (Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
for (const Map<String, List<String>>::Element *E = props.front(); E; E = E->next()) {
if (E != props.front()) {
file->store_string("\n");
}
Expand Down Expand Up @@ -831,19 +831,19 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
Set<_VCSort> vclist;

if (p_merge_with_current) {
for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
const VariantContainer *v = &G->get();
for (const KeyValue<StringName, VariantContainer> &G : props) {
const VariantContainer *v = &G.value;

if (v->hide_from_editor) {
continue;
}

if (p_custom.has(G->key())) {
if (p_custom.has(G.key)) {
continue;
}

_VCSort vc;
vc.name = G->key(); //*k;
vc.name = G.key; //*k;
vc.order = v->order;
vc.type = v->variant.get_type();
vc.flags = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE;
Expand All @@ -855,14 +855,14 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
}
}

for (const Map<String, Variant>::Element *E = p_custom.front(); E; E = E->next()) {
for (const KeyValue<String, Variant> &E : p_custom) {
// Lookup global prop to store in the same order
Map<StringName, VariantContainer>::Element *global_prop = props.find(E->key());
Map<StringName, VariantContainer>::Element *global_prop = props.find(E.key);

_VCSort vc;
vc.name = E->key();
vc.name = E.key;
vc.order = global_prop ? global_prop->get().order : 0xFFFFFFF;
vc.type = E->get().get_type();
vc.type = E.value.get_type();
vc.flags = PROPERTY_USAGE_STORAGE;
vclist.insert(vc);
}
Expand Down
8 changes: 4 additions & 4 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2411,12 +2411,12 @@ Error EngineDebugger::call_capture(void *p_user, const String &p_cmd, const Arra
}

EngineDebugger::~EngineDebugger() {
for (Map<StringName, Callable>::Element *E = captures.front(); E; E = E->next()) {
::EngineDebugger::unregister_message_capture(E->key());
for (const KeyValue<StringName, Callable> &E : captures) {
::EngineDebugger::unregister_message_capture(E.key);
}
captures.clear();
for (Map<StringName, ProfilerCallable>::Element *E = profilers.front(); E; E = E->next()) {
::EngineDebugger::unregister_profiler(E->key());
for (const KeyValue<StringName, ProfilerCallable> &E : profilers) {
::EngineDebugger::unregister_profiler(E.key);
}
profilers.clear();
}
Expand Down
10 changes: 5 additions & 5 deletions core/debugger/engine_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ void EngineDebugger::iteration(uint64_t p_frame_ticks, uint64_t p_process_ticks,
physics_time = USEC_TO_SEC(p_physics_ticks);
physics_frame_time = p_physics_frame_time;
// Notify tick to running profilers
for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) {
Profiler &p = E->get();
for (KeyValue<StringName, Profiler> &E : profilers) {
Profiler &p = E.value;
if (!p.active || !p.tick) {
continue;
}
Expand Down Expand Up @@ -179,9 +179,9 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
void EngineDebugger::deinitialize() {
if (singleton) {
// Stop all profilers
for (Map<StringName, Profiler>::Element *E = profilers.front(); E; E = E->next()) {
if (E->get().active) {
singleton->profiler_enable(E->key(), false);
for (const KeyValue<StringName, Profiler> &E : profilers) {
if (E.value.active) {
singleton->profiler_enable(E.key, false);
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/debugger/local_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {

} else if (line.begins_with("set")) {
if (line.get_slice_count(" ") == 1) {
for (Map<String, String>::Element *E = options.front(); E; E = E->next()) {
print_line("\t" + E->key() + "=" + E->value());
for (const KeyValue<String, String> &E : options) {
print_line("\t" + E.key + "=" + E.value);
}

} else {
Expand Down Expand Up @@ -249,8 +249,8 @@ void LocalDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
}

print_line("Breakpoint(s): " + itos(breakpoints.size()));
for (Map<int, Set<StringName>>::Element *E = breakpoints.front(); E; E = E->next()) {
print_line("\t" + String(E->value().front()->get()) + ":" + itos(E->key()));
for (const KeyValue<int, Set<StringName>> &E : breakpoints) {
print_line("\t" + String(E.value.front()->get()) + ":" + itos(E.key));
}

} else {
Expand Down
4 changes: 2 additions & 2 deletions core/debugger/remote_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ struct RemoteDebugger::NetworkProfiler {
if (pt - last_profile_time > 100) {
last_profile_time = pt;
DebuggerMarshalls::NetworkProfilerFrame frame;
for (Map<ObjectID, NodeInfo>::Element *E = multiplayer_node_data.front(); E; E = E->next()) {
frame.infos.push_back(E->get());
for (const KeyValue<ObjectID, NodeInfo> &E : multiplayer_node_data) {
frame.infos.push_back(E.value);
}
multiplayer_node_data.clear();
EngineDebugger::get_singleton()->send_message("network:profile_frame", frame.serialize());
Expand Down
6 changes: 3 additions & 3 deletions core/extension/extension_api_dump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ Dictionary NativeExtensionAPIDump::generate_extension_api() {
api_dump["global_constants"] = constants;

Array enums;
for (Map<String, List<Pair<String, int>>>::Element *E = enum_list.front(); E; E = E->next()) {
for (const KeyValue<String, List<Pair<String, int>>> &E : enum_list) {
Dictionary d1;
d1["name"] = E->key();
d1["name"] = E.key;
Array values;
for (const Pair<String, int> &F : E->get()) {
for (const Pair<String, int> &F : E.value) {
Dictionary d2;
d2["name"] = F.first;
d2["value"] = F.second;
Expand Down
12 changes: 6 additions & 6 deletions core/extension/native_extension_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ bool NativeExtensionManager::is_extension_loaded(const String &p_path) const {

Vector<String> NativeExtensionManager::get_loaded_extensions() const {
Vector<String> ret;
for (const Map<String, Ref<NativeExtension>>::Element *E = native_extension_map.front(); E; E = E->next()) {
ret.push_back(E->key());
for (const KeyValue<String, Ref<NativeExtension>> &E : native_extension_map) {
ret.push_back(E.key);
}
return ret;
}
Expand All @@ -97,16 +97,16 @@ Ref<NativeExtension> NativeExtensionManager::get_extension(const String &p_path)

void NativeExtensionManager::initialize_extensions(NativeExtension::InitializationLevel p_level) {
ERR_FAIL_COND(int32_t(p_level) - 1 != level);
for (Map<String, Ref<NativeExtension>>::Element *E = native_extension_map.front(); E; E = E->next()) {
E->get()->initialize_library(p_level);
for (KeyValue<String, Ref<NativeExtension>> &E : native_extension_map) {
E.value->initialize_library(p_level);
}
level = p_level;
}

void NativeExtensionManager::deinitialize_extensions(NativeExtension::InitializationLevel p_level) {
ERR_FAIL_COND(int32_t(p_level) != level);
for (Map<String, Ref<NativeExtension>>::Element *E = native_extension_map.front(); E; E = E->next()) {
E->get()->deinitialize_library(p_level);
for (KeyValue<String, Ref<NativeExtension>> &E : native_extension_map) {
E.value->deinitialize_library(p_level);
}
level = int32_t(p_level) - 1;
}
Expand Down
14 changes: 7 additions & 7 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,9 +863,9 @@ void Input::release_pressed_events() {
joy_buttons_pressed.clear();
_joy_axis.clear();

for (Map<StringName, Input::Action>::Element *E = action_state.front(); E; E = E->next()) {
if (E->get().pressed) {
action_release(E->key());
for (const KeyValue<StringName, Input::Action> &E : action_state) {
if (E.value.pressed) {
action_release(E.key);
}
}
}
Expand Down Expand Up @@ -1322,8 +1322,8 @@ void Input::add_joy_mapping(String p_mapping, bool p_update_existing) {
if (p_update_existing) {
Vector<String> entry = p_mapping.split(",");
String uid = entry[0];
for (Map<int, Joypad>::Element *E = joy_names.front(); E; E = E->next()) {
Joypad &joy = E->get();
for (KeyValue<int, Joypad> &E : joy_names) {
Joypad &joy = E.value;
if (joy.uid == uid) {
joy.mapping = map_db.size() - 1;
}
Expand All @@ -1337,8 +1337,8 @@ void Input::remove_joy_mapping(String p_guid) {
map_db.remove(i);
}
}
for (Map<int, Joypad>::Element *E = joy_names.front(); E; E = E->next()) {
Joypad &joy = E->get();
for (KeyValue<int, Joypad> &E : joy_names) {
Joypad &joy = E.value;
if (joy.uid == p_guid) {
joy.mapping = -1;
}
Expand Down
8 changes: 4 additions & 4 deletions core/io/file_access_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ PackedData::PackedData() {
}

void PackedData::_free_packed_dirs(PackedDir *p_dir) {
for (Map<String, PackedDir *>::Element *E = p_dir->subdirs.front(); E; E = E->next()) {
_free_packed_dirs(E->get());
for (const KeyValue<String, PackedDir *> &E : p_dir->subdirs) {
_free_packed_dirs(E.value);
}
memdelete(p_dir);
}
Expand Down Expand Up @@ -395,8 +395,8 @@ Error DirAccessPack::list_dir_begin() {
list_dirs.clear();
list_files.clear();

for (Map<String, PackedData::PackedDir *>::Element *E = current->subdirs.front(); E; E = E->next()) {
list_dirs.push_back(E->key());
for (const KeyValue<String, PackedData::PackedDir *> &E : current->subdirs) {
list_dirs.push_back(E.key);
}

for (Set<String>::Element *E = current->files.front(); E; E = E->next()) {
Expand Down
8 changes: 4 additions & 4 deletions core/io/ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ Array IP::_get_local_interfaces() const {
Array results;
Map<String, Interface_Info> interfaces;
get_local_interfaces(&interfaces);
for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) {
Interface_Info &c = E->get();
for (KeyValue<String, Interface_Info> &E : interfaces) {
Interface_Info &c = E.value;
Dictionary rc;
rc["name"] = c.name;
rc["friendly"] = c.name_friendly;
Expand All @@ -310,8 +310,8 @@ Array IP::_get_local_interfaces() const {
void IP::get_local_addresses(List<IPAddress> *r_addresses) const {
Map<String, Interface_Info> interfaces;
get_local_interfaces(&interfaces);
for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) {
for (const IPAddress &F : E->get().ip_addresses) {
for (const KeyValue<String, Interface_Info> &E : interfaces) {
for (const IPAddress &F : E.value.ip_addresses) {
r_addresses->push_front(F);
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,9 @@ void ResourceCache::dump(const char *p_file, bool p_short) {
}
}

for (Map<String, int>::Element *E = type_count.front(); E; E = E->next()) {
for (const KeyValue<String, int> &E : type_count) {
if (f) {
f->store_line(E->key() + " count: " + itos(E->get()));
f->store_line(E.key + " count: " + itos(E.value));
}
}
if (f) {
Expand Down
4 changes: 2 additions & 2 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,8 +1960,8 @@ Error ResourceFormatSaverBinaryInstance::save(const String &p_path, const RES &p
Vector<RES> save_order;
save_order.resize(external_resources.size());

for (Map<RES, int>::Element *E = external_resources.front(); E; E = E->next()) {
save_order.write[E->get()] = E->key();
for (const KeyValue<RES, int> &E : external_resources) {
save_order.write[E.value] = E.key;
}

for (int i = 0; i < save_order.size(); i++) {
Expand Down
4 changes: 2 additions & 2 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *

Error ResourceFormatLoader::rename_dependencies(const String &p_path, const Map<String, String> &p_map) {
Dictionary deps_dict;
for (Map<String, String>::Element *E = p_map.front(); E; E = E->next()) {
deps_dict[E->key()] = E->value();
for (KeyValue<String, String> E : p_map) {
deps_dict[E.key] = E.value;
}

int64_t err;
Expand Down
24 changes: 12 additions & 12 deletions core/math/quick_hull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
//create new faces from horizon edges
List<List<Face>::Element *> new_faces; //new faces

for (Map<Edge, FaceConnect>::Element *E = lit_edges.front(); E; E = E->next()) {
FaceConnect &fc = E->get();
for (KeyValue<Edge, FaceConnect> &E : lit_edges) {
FaceConnect &fc = E.value;
if (fc.left && fc.right) {
continue; //edge is uninteresting, not on horizon
}
Expand All @@ -275,8 +275,8 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_

Face face;
face.vertices[0] = f.points_over[next];
face.vertices[1] = E->key().vertices[0];
face.vertices[2] = E->key().vertices[1];
face.vertices[1] = E.key.vertices[0];
face.vertices[2] = E.key.vertices[1];

Plane p(p_points[face.vertices[0]], p_points[face.vertices[1]], p_points[face.vertices[2]]);

Expand Down Expand Up @@ -418,13 +418,13 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
}

// remove all edge connections to this face
for (Map<Edge, RetFaceConnect>::Element *G = ret_edges.front(); G; G = G->next()) {
if (G->get().left == O) {
G->get().left = nullptr;
for (KeyValue<Edge, RetFaceConnect> &G : ret_edges) {
if (G.value.left == O) {
G.value.left = nullptr;
}

if (G->get().right == O) {
G->get().right = nullptr;
if (G.value.right == O) {
G.value.right = nullptr;
}
}

Expand All @@ -444,10 +444,10 @@ Error QuickHull::build(const Vector<Vector3> &p_points, Geometry3D::MeshData &r_
}
r_mesh.edges.resize(ret_edges.size());
idx = 0;
for (Map<Edge, RetFaceConnect>::Element *E = ret_edges.front(); E; E = E->next()) {
for (const KeyValue<Edge, RetFaceConnect> &E : ret_edges) {
Geometry3D::MeshData::Edge e;
e.a = E->key().vertices[0];
e.b = E->key().vertices[1];
e.a = E.key.vertices[0];
e.b = E.key.vertices[1];
r_mesh.edges.write[idx++] = e;
}

Expand Down
Loading

0 comments on commit 77721b3

Please sign in to comment.