From ac3322b0af8f23e8e2dac8111200bc69b5604c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sat, 24 Jul 2021 15:46:25 +0200 Subject: Use const references where possible for List range iterators --- modules/visual_script/visual_script.cpp | 8 ++--- modules/visual_script/visual_script_editor.cpp | 36 +++++++++++----------- .../visual_script/visual_script_flow_control.cpp | 2 +- modules/visual_script/visual_script_func_nodes.cpp | 24 +++++++-------- modules/visual_script/visual_script_nodes.cpp | 20 ++++++------ .../visual_script_property_selector.cpp | 6 ++-- .../visual_script/visual_script_yield_nodes.cpp | 4 +-- 7 files changed, 50 insertions(+), 50 deletions(-) (limited to 'modules/visual_script') diff --git a/modules/visual_script/visual_script.cpp b/modules/visual_script/visual_script.cpp index 5828529103..7a2404fd80 100644 --- a/modules/visual_script/visual_script.cpp +++ b/modules/visual_script/visual_script.cpp @@ -752,7 +752,7 @@ void VisualScript::_update_placeholders() { List keys; variables.get_key_list(&keys); - for (StringName &E : keys) { + for (const StringName &E : keys) { if (!variables[E]._export) { continue; } @@ -874,7 +874,7 @@ void VisualScript::get_script_method_list(List *p_list) const { List funcs; functions.get_key_list(&funcs); - for (StringName &E : funcs) { + for (const StringName &E : funcs) { MethodInfo mi; mi.name = E; if (functions[E].func_id >= 0) { @@ -928,7 +928,7 @@ void VisualScript::get_script_property_list(List *p_list) const { List vars; get_variable_list(&vars); - for (StringName &E : vars) { + for (const StringName &E : vars) { //if (!variables[E]._export) // continue; PropertyInfo pi = variables[E].info; @@ -2467,7 +2467,7 @@ void VisualScriptLanguage::debug_get_stack_level_members(int p_level, List vars; vs->get_variable_list(&vars); - for (StringName &E : vars) { + for (const StringName &E : vars) { Variant v; if (_call_stack[l].instance->get_variable(E, &v)) { p_members->push_back("variables/" + E); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 16313d58d0..00dba117fb 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -561,7 +561,7 @@ void VisualScriptEditor::_update_graph_connections() { List sequence_conns; script->get_sequence_connection_list(&sequence_conns); - for (VisualScript::SequenceConnection &E : sequence_conns) { + for (const VisualScript::SequenceConnection &E : sequence_conns) { graph->connect_node(itos(E.from_node), E.from_output, itos(E.to_node), 0); } @@ -1045,7 +1045,7 @@ void VisualScriptEditor::_update_members() { List func_names; script->get_function_list(&func_names); func_names.sort_custom(); - for (StringName &E : func_names) { + for (const StringName &E : func_names) { TreeItem *ti = members->create_item(functions); ti->set_text(0, E); ti->set_selectable(0, true); @@ -1099,7 +1099,7 @@ void VisualScriptEditor::_update_members() { List var_names; script->get_variable_list(&var_names); - for (StringName &E : var_names) { + for (const StringName &E : var_names) { TreeItem *ti = members->create_item(variables); ti->set_text(0, E); @@ -1123,7 +1123,7 @@ void VisualScriptEditor::_update_members() { List signal_names; script->get_custom_signal_list(&signal_names); - for (StringName &E : signal_names) { + for (const StringName &E : signal_names) { TreeItem *ti = members->create_item(_signals); ti->set_text(0, E); ti->set_selectable(0, true); @@ -1705,7 +1705,7 @@ void VisualScriptEditor::_on_nodes_delete() { List sequence_conns; script->get_sequence_connection_list(&sequence_conns); - for (VisualScript::SequenceConnection &E : sequence_conns) { + for (const VisualScript::SequenceConnection &E : sequence_conns) { if (E.from_node == cr_node || E.to_node == cr_node) { undo_redo->add_undo_method(script.ptr(), "sequence_connect", E.from_node, E.from_output, E.to_node); } @@ -1714,7 +1714,7 @@ void VisualScriptEditor::_on_nodes_delete() { List data_conns; script->get_data_connection_list(&data_conns); - for (VisualScript::DataConnection &E : data_conns) { + for (const VisualScript::DataConnection &E : data_conns) { if (E.from_node == F || E.to_node == F) { undo_redo->add_undo_method(script.ptr(), "data_connect", E.from_node, E.from_port, E.to_node, E.to_port); } @@ -1765,7 +1765,7 @@ void VisualScriptEditor::_on_nodes_duplicate() { List seqs; script->get_sequence_connection_list(&seqs); - for (VisualScript::SequenceConnection &E : seqs) { + for (const VisualScript::SequenceConnection &E : seqs) { if (to_duplicate.has(E.from_node) && to_duplicate.has(E.to_node)) { undo_redo->add_do_method(script.ptr(), "sequence_connect", remap[E.from_node], E.from_output, remap[E.to_node]); } @@ -1773,7 +1773,7 @@ void VisualScriptEditor::_on_nodes_duplicate() { List data; script->get_data_connection_list(&data); - for (VisualScript::DataConnection &E : data) { + for (const VisualScript::DataConnection &E : data) { if (to_duplicate.has(E.from_node) && to_duplicate.has(E.to_node)) { undo_redo->add_do_method(script.ptr(), "data_connect", remap[E.from_node], E.from_port, remap[E.to_node], E.to_port); } @@ -2552,7 +2552,7 @@ void VisualScriptEditor::goto_line(int p_line, bool p_with_error) { List functions; script->get_function_list(&functions); - for (StringName &E : functions) { + for (const StringName &E : functions) { if (script->has_node(p_line)) { _update_graph(); _update_members(); @@ -2773,7 +2773,7 @@ void VisualScriptEditor::_remove_node(int p_id) { List sequence_conns; script->get_sequence_connection_list(&sequence_conns); - for (VisualScript::SequenceConnection &E : sequence_conns) { + for (const VisualScript::SequenceConnection &E : sequence_conns) { if (E.from_node == p_id || E.to_node == p_id) { undo_redo->add_undo_method(script.ptr(), "sequence_connect", E.from_node, E.from_output, E.to_node); } @@ -2782,7 +2782,7 @@ void VisualScriptEditor::_remove_node(int p_id) { List data_conns; script->get_data_connection_list(&data_conns); - for (VisualScript::DataConnection &E : data_conns) { + for (const VisualScript::DataConnection &E : data_conns) { if (E.from_node == p_id || E.to_node == p_id) { undo_redo->add_undo_method(script.ptr(), "data_connect", E.from_node, E.from_port, E.to_node, E.to_port); } @@ -2802,7 +2802,7 @@ bool VisualScriptEditor::node_has_sequence_connections(int p_id) { List sequence_conns; script->get_sequence_connection_list(&sequence_conns); - for (VisualScript::SequenceConnection &E : sequence_conns) { + for (const VisualScript::SequenceConnection &E : sequence_conns) { int from = E.from_node; int to = E.to_node; @@ -3460,7 +3460,7 @@ void VisualScriptEditor::_selected_new_virtual_method(const String &p_text, cons List methods; bool found = false; ClassDB::get_virtual_methods(script->get_instance_base_type(), &methods); - for (MethodInfo &E : methods) { + for (const MethodInfo &E : methods) { if (E.name == name) { minfo = E; found = true; @@ -3732,7 +3732,7 @@ void VisualScriptEditor::_menu_option(int p_what) { _update_graph(); - for (String &E : reselect) { + for (const String &E : reselect) { GraphNode *gn = Object::cast_to(graph->get_node(E)); gn->set_selected(true); } @@ -3772,7 +3772,7 @@ void VisualScriptEditor::_menu_option(int p_what) { List sequence_connections; script->get_sequence_connection_list(&sequence_connections); - for (VisualScript::SequenceConnection &E : sequence_connections) { + for (const VisualScript::SequenceConnection &E : sequence_connections) { if (clipboard->nodes.has(E.from_node) && clipboard->nodes.has(E.to_node)) { clipboard->sequence_connections.insert(E); } @@ -3781,7 +3781,7 @@ void VisualScriptEditor::_menu_option(int p_what) { List data_connections; script->get_data_connection_list(&data_connections); - for (VisualScript::DataConnection &E : data_connections) { + for (const VisualScript::DataConnection &E : data_connections) { if (clipboard->nodes.has(E.from_node) && clipboard->nodes.has(E.to_node)) { clipboard->data_connections.insert(E); } @@ -3933,7 +3933,7 @@ void VisualScriptEditor::_menu_option(int p_what) { // Pick the node with input sequence. Set nodes_from; Set nodes_to; - for (VisualScript::SequenceConnection &E : seqs) { + for (const VisualScript::SequenceConnection &E : seqs) { if (nodes.has(E.from_node) && nodes.has(E.to_node)) { seqmove.insert(E); nodes_from.insert(E.from_node); @@ -3976,7 +3976,7 @@ void VisualScriptEditor::_menu_option(int p_what) { { List dats; script->get_data_connection_list(&dats); - for (VisualScript::DataConnection &E : dats) { + for (const VisualScript::DataConnection &E : dats) { if (nodes.has(E.from_node) && nodes.has(E.to_node)) { datamove.insert(E); } else if (!nodes.has(E.from_node) && nodes.has(E.to_node)) { diff --git a/modules/visual_script/visual_script_flow_control.cpp b/modules/visual_script/visual_script_flow_control.cpp index ddf6169015..62a4f465cb 100644 --- a/modules/visual_script/visual_script_flow_control.cpp +++ b/modules/visual_script/visual_script_flow_control.cpp @@ -852,7 +852,7 @@ void VisualScriptTypeCast::_bind_methods() { } String script_ext_hint; - for (String &E : script_extensions) { + for (const String &E : script_extensions) { if (script_ext_hint != String()) { script_ext_hint += ","; } diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index c694d6b8e0..6ba5ad4fd6 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -538,7 +538,7 @@ void VisualScriptFunctionCall::_validate_property(PropertyInfo &property) const Engine::get_singleton()->get_singletons(&names); property.hint = PROPERTY_HINT_ENUM; String sl; - for (Engine::Singleton &E : names) { + for (const Engine::Singleton &E : names) { if (sl != String()) { sl += ","; } @@ -683,7 +683,7 @@ void VisualScriptFunctionCall::_bind_methods() { } String script_ext_hint; - for (String &E : script_extensions) { + for (const String &E : script_extensions) { if (script_ext_hint != String()) { script_ext_hint += ","; } @@ -1004,7 +1004,7 @@ PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const List props; ClassDB::get_property_list(_get_base_type(), &props, false); - for (PropertyInfo &E : props) { + for (const PropertyInfo &E : props) { if (E.name == property) { String detail_prop_name = property; if (index != StringName()) { @@ -1135,7 +1135,7 @@ void VisualScriptPropertySet::_update_cache() { List pinfo; v.get_property_list(&pinfo); - for (PropertyInfo &E : pinfo) { + for (const PropertyInfo &E : pinfo) { if (E.name == property) { type_cache = E; } @@ -1186,7 +1186,7 @@ void VisualScriptPropertySet::_update_cache() { script->get_script_property_list(&pinfo); } - for (PropertyInfo &E : pinfo) { + for (const PropertyInfo &E : pinfo) { if (E.name == property) { type_cache = E; return; @@ -1354,7 +1354,7 @@ void VisualScriptPropertySet::_validate_property(PropertyInfo &property) const { List plist; v.get_property_list(&plist); String options = ""; - for (PropertyInfo &E : plist) { + for (const PropertyInfo &E : plist) { options += "," + E.name; } @@ -1410,7 +1410,7 @@ void VisualScriptPropertySet::_bind_methods() { } String script_ext_hint; - for (String &E : script_extensions) { + for (const String &E : script_extensions) { if (script_ext_hint != String()) { script_ext_hint += ","; } @@ -1820,7 +1820,7 @@ void VisualScriptPropertyGet::_update_cache() { List pinfo; v.get_property_list(&pinfo); - for (PropertyInfo &E : pinfo) { + for (const PropertyInfo &E : pinfo) { if (E.name == property) { type_cache = E.type; return; @@ -2059,7 +2059,7 @@ void VisualScriptPropertyGet::_validate_property(PropertyInfo &property) const { List plist; v.get_property_list(&plist); String options = ""; - for (PropertyInfo &E : plist) { + for (const PropertyInfo &E : plist) { options += "," + E.name; } @@ -2112,7 +2112,7 @@ void VisualScriptPropertyGet::_bind_methods() { } String script_ext_hint; - for (String &E : script_extensions) { + for (const String &E : script_extensions) { if (script_ext_hint != String()) { script_ext_hint += ","; } @@ -2323,7 +2323,7 @@ void VisualScriptEmitSignal::_validate_property(PropertyInfo &property) const { } String ml; - for (StringName &E : sigs) { + for (const StringName &E : sigs) { if (ml != String()) { ml += ","; } @@ -2418,7 +2418,7 @@ void register_visual_script_func_nodes() { List ml; vt.get_method_list(&ml); - for (MethodInfo &E : ml) { + for (const MethodInfo &E : ml) { VisualScriptLanguage::singleton->add_register_func("functions/by_type/" + type_name + "/" + E.name, create_basic_type_call_node); } } diff --git a/modules/visual_script/visual_script_nodes.cpp b/modules/visual_script/visual_script_nodes.cpp index e6511792aa..c517d89aa5 100644 --- a/modules/visual_script/visual_script_nodes.cpp +++ b/modules/visual_script/visual_script_nodes.cpp @@ -1306,7 +1306,7 @@ void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const { vs->get_variable_list(&vars); String vhint; - for (StringName &E : vars) { + for (const StringName &E : vars) { if (vhint != String()) { vhint += ","; } @@ -1416,7 +1416,7 @@ void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const { vs->get_variable_list(&vars); String vhint; - for (StringName &E : vars) { + for (const StringName &E : vars) { if (vhint != String()) { vhint += ","; } @@ -1944,7 +1944,7 @@ void VisualScriptClassConstant::set_base_type(const StringName &p_which) { ClassDB::get_integer_constant_list(base_type, &constants, true); if (constants.size() > 0) { bool found_name = false; - for (String &E : constants) { + for (const String &E : constants) { if (E == name) { found_name = true; break; @@ -1993,7 +1993,7 @@ void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const ClassDB::get_integer_constant_list(base_type, &constants, true); property.hint_string = ""; - for (String &E : constants) { + for (const String &E : constants) { if (property.hint_string != String()) { property.hint_string += ","; } @@ -2078,7 +2078,7 @@ void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) { Variant::get_constants_for_type(type, &constants); if (constants.size() > 0) { bool found_name = false; - for (StringName &E : constants) { + for (const StringName &E : constants) { if (E == name) { found_name = true; break; @@ -2131,7 +2131,7 @@ void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) c return; } property.hint_string = ""; - for (StringName &E : constants) { + for (const StringName &E : constants) { if (property.hint_string != String()) { property.hint_string += ","; } @@ -2358,7 +2358,7 @@ void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) con Engine::get_singleton()->get_singletons(&singletons); - for (Engine::Singleton &E : singletons) { + for (const Engine::Singleton &E : singletons) { if (E.name == "VS" || E.name == "PS" || E.name == "PS2D" || E.name == "AS" || E.name == "TS" || E.name == "SS" || E.name == "SS2D") { continue; //skip these, too simple named } @@ -3749,7 +3749,7 @@ void VisualScriptInputAction::_validate_property(PropertyInfo &property) const { ProjectSettings::get_singleton()->get_property_list(&pinfo); Vector al; - for (PropertyInfo &pi : pinfo) { + for (const PropertyInfo &pi : pinfo) { if (!pi.name.begins_with("input/")) { continue; } @@ -3842,7 +3842,7 @@ void VisualScriptDeconstruct::_update_elements() { List pinfo; v.get_property_list(&pinfo); - for (PropertyInfo &E : pinfo) { + for (const PropertyInfo &E : pinfo) { Element e; e.name = E.name; e.type = E.type; @@ -4023,7 +4023,7 @@ void register_visual_script_nodes() { List constructors; Variant::get_constructor_list(Variant::Type(i), &constructors); - for (MethodInfo &E : constructors) { + for (const MethodInfo &E : constructors) { if (E.arguments.size() > 0) { String name = "functions/constructors/" + Variant::get_type_name(Variant::Type(i)) + "("; for (int j = 0; j < E.arguments.size(); j++) { diff --git a/modules/visual_script/visual_script_property_selector.cpp b/modules/visual_script/visual_script_property_selector.cpp index 5e9ecbe615..8bf1c6cbfa 100644 --- a/modules/visual_script/visual_script_property_selector.cpp +++ b/modules/visual_script/visual_script_property_selector.cpp @@ -93,7 +93,7 @@ void VisualScriptPropertySelector::_update_search() { base = ClassDB::get_parent_class_nocheck(base); } - for (StringName &E : base_list) { + for (const StringName &E : base_list) { List methods; List props; TreeItem *category = nullptr; @@ -157,7 +157,7 @@ void VisualScriptPropertySelector::_update_search() { ClassDB::get_property_list(E, &props, true); } } - for (PropertyInfo &F : props) { + for (const PropertyInfo &F : props) { if (!(F.usage & PROPERTY_USAGE_EDITOR) && !(F.usage & PROPERTY_USAGE_SCRIPT_VARIABLE)) { continue; } @@ -340,7 +340,7 @@ void VisualScriptPropertySelector::get_visual_node_names(const String &root_filt List fnodes; VisualScriptLanguage::singleton->get_registered_node_names(&fnodes); - for (String &E : fnodes) { + for (const String &E : fnodes) { if (!E.begins_with(root_filter)) { continue; } diff --git a/modules/visual_script/visual_script_yield_nodes.cpp b/modules/visual_script/visual_script_yield_nodes.cpp index bf269b1d7a..9fa49b8a1d 100644 --- a/modules/visual_script/visual_script_yield_nodes.cpp +++ b/modules/visual_script/visual_script_yield_nodes.cpp @@ -438,7 +438,7 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { ClassDB::get_signal_list(_get_base_type(), &methods); List mstring; - for (MethodInfo &E : methods) { + for (const MethodInfo &E : methods) { if (E.name.begins_with("_")) { continue; } @@ -448,7 +448,7 @@ void VisualScriptYieldSignal::_validate_property(PropertyInfo &property) const { mstring.sort(); String ml; - for (String &E : mstring) { + for (const String &E : mstring) { if (ml != String()) { ml += ","; } -- cgit v1.2.3