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 --- scene/resources/curve.cpp | 4 ++-- scene/resources/material.cpp | 2 +- scene/resources/navigation_mesh.cpp | 4 ++-- scene/resources/packed_scene.cpp | 12 ++++++------ scene/resources/resource_format_text.cpp | 4 ++-- scene/resources/sprite_frames.cpp | 2 +- scene/resources/syntax_highlighter.cpp | 2 +- scene/resources/theme.cpp | 2 +- scene/resources/tile_set.cpp | 10 +++++----- scene/resources/visual_shader.cpp | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) (limited to 'scene/resources') diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index 71b4542970..c13db83d6d 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -729,7 +729,7 @@ void Curve2D::_bake() const { Vector2 *w = baked_point_cache.ptrw(); int idx = 0; - for (Vector2 &E : pointlist) { + for (const Vector2 &E : pointlist) { w[idx] = E; idx++; } @@ -1239,7 +1239,7 @@ void Curve3D::_bake() const { Vector3 prev_up = Vector3(0, 1, 0); Vector3 prev_forward = Vector3(0, 0, 1); - for (Plane &E : pointlist) { + for (const Plane &E : pointlist) { w[idx] = E.normal; wt[idx] = E.d; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index fbeb331f13..08f7274ff6 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -278,7 +278,7 @@ void ShaderMaterial::get_argument_options(const StringName &p_function, int p_id if (shader.is_valid()) { List pl; shader->get_param_list(&pl); - for (PropertyInfo &E : pl) { + for (const PropertyInfo &E : pl) { r_options->push_back(quote_style + E.name.replace_first("shader_param/", "") + quote_style); } } diff --git a/scene/resources/navigation_mesh.cpp b/scene/resources/navigation_mesh.cpp index d679a17c15..ddc50c0490 100644 --- a/scene/resources/navigation_mesh.cpp +++ b/scene/resources/navigation_mesh.cpp @@ -329,7 +329,7 @@ Ref NavigationMesh::get_debug_mesh() { Vector3 *tw = tmeshfaces.ptrw(); int tidx = 0; - for (Face3 &f : faces) { + for (const Face3 &f : faces) { for (int j = 0; j < 3; j++) { tw[tidx++] = f.vertex[j]; _EdgeKey ek; @@ -364,7 +364,7 @@ Ref NavigationMesh::get_debug_mesh() { { Vector3 *w = varr.ptrw(); int idx = 0; - for (Vector3 &E : lines) { + for (const Vector3 &E : lines) { w[idx++] = E; } } diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 8018ce3a9b..eddbb9a842 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -206,7 +206,7 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { node->set(snames[nprops[j].name], props[nprops[j].value], &valid); //restore old state for new script, if exists - for (Pair &E : old_state) { + for (const Pair &E : old_state) { node->set(E.first, E.second); } } else { @@ -477,7 +477,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map script->update_exports(); } - for (PropertyInfo &E : plist) { + for (const PropertyInfo &E : plist) { if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } @@ -565,7 +565,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map List groups; p_node->get_groups(&groups); - for (Node::GroupInfo &gi : groups) { + for (const Node::GroupInfo &gi : groups) { if (!gi.persistent) { continue; } @@ -575,7 +575,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map */ bool skip = false; - for (PackState &F : pack_state_stack) { + for (const PackState &F : pack_state_stack) { //check all levels of pack to see if the group was added somewhere const PackState &ps = F; if (ps.state->is_node_in_group(ps.node, gi.name)) { @@ -677,13 +677,13 @@ Error SceneState::_parse_connections(Node *p_owner, Node *p_node, Map conns; p_node->get_signal_connection_list(E.name, &conns); conns.sort(); - for (Node::Connection &F : conns) { + for (const Node::Connection &F : conns) { const Node::Connection &c = F; if (!(c.flags & CONNECT_PERSIST)) { //only persistent connections get saved diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index 615187ab7f..c53a681275 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -1221,7 +1221,7 @@ Error ResourceLoaderText::save_as_binary(FileAccess *p_f, const String &p_path) int prop_count = 0; - for (PropertyInfo &E : props) { + for (const PropertyInfo &E : props) { if (!(E.usage & PROPERTY_USAGE_STORAGE)) { continue; } @@ -1581,7 +1581,7 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, Dictionary d = p_variant; List keys; d.get_key_list(&keys); - for (Variant &E : keys) { + for (const Variant &E : keys) { Variant v = d[E]; _find_resources(v); } diff --git a/scene/resources/sprite_frames.cpp b/scene/resources/sprite_frames.cpp index 5fdabb6f0f..e9adf67559 100644 --- a/scene/resources/sprite_frames.cpp +++ b/scene/resources/sprite_frames.cpp @@ -100,7 +100,7 @@ Vector SpriteFrames::_get_animation_list() const { Vector ret; List al; get_animation_list(&al); - for (StringName &E : al) { + for (const StringName &E : al) { ret.push_back(E); } diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp index ac6bffb20b..173ce2adce 100644 --- a/scene/resources/syntax_highlighter.cpp +++ b/scene/resources/syntax_highlighter.cpp @@ -529,7 +529,7 @@ void CodeHighlighter::set_color_regions(const Dictionary &p_color_regions) { List keys; p_color_regions.get_key_list(&keys); - for (Variant &E : keys) { + for (const Variant &E : keys) { String key = E; String start_key = key.get_slice(" ", 0); diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 5eb35ce3ff..e4a731c7f7 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -447,7 +447,7 @@ void Theme::_get_property_list(List *p_list) const { // Sort and store properties. list.sort(); - for (PropertyInfo &E : list) { + for (const PropertyInfo &E : list) { p_list->push_back(E); } } diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 2ab9d4b5a3..45e981271f 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -4357,13 +4357,13 @@ void TileSetPluginAtlasRendering::update_dirty_quadrants(TileMap *p_tile_map, Se RenderingServer *rs = RenderingServer::get_singleton(); // Free the canvas items. - for (RID E : q.canvas_items) { + for (const RID &E : q.canvas_items) { rs->free(E); } q.canvas_items.clear(); // Free the occluders. - for (RID E : q.occluders) { + for (const RID &E : q.occluders) { rs->free(E); } q.occluders.clear(); @@ -4473,7 +4473,7 @@ void TileSetPluginAtlasRendering::update_dirty_quadrants(TileMap *p_tile_map, Se // Sort the quadrants for (Map::Element *E = world_to_map.front(); E; E = E->next()) { TileMapQuadrant &q = quadrant_map[E->value()]; - for (RID F : q.canvas_items) { + for (const RID &F : q.canvas_items) { RS::get_singleton()->canvas_item_set_draw_index(F, index++); } } @@ -4491,13 +4491,13 @@ void TileSetPluginAtlasRendering::create_quadrant(TileMap *p_tile_map, TileMapQu void TileSetPluginAtlasRendering::cleanup_quadrant(TileMap *p_tile_map, TileMapQuadrant *p_quadrant) { // Free the canvas items. - for (RID E : p_quadrant->canvas_items) { + for (const RID &E : p_quadrant->canvas_items) { RenderingServer::get_singleton()->free(E); } p_quadrant->canvas_items.clear(); // Free the occluders. - for (RID E : p_quadrant->occluders) { + for (const RID &E : p_quadrant->occluders) { RenderingServer::get_singleton()->free(E); } p_quadrant->occluders.clear(); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 752c026aa6..7292728251 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -739,7 +739,7 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port, ERR_FAIL_COND_V_MSG(!is_port_types_compatible(from_port_type, to_port_type), ERR_INVALID_PARAMETER, "Incompatible port types (scalar/vec/bool) with transform."); - for (Connection &E : g->connections) { + for (const Connection &E : g->connections) { if (E.from_node == p_from_node && E.from_port == p_from_port && E.to_node == p_to_node && E.to_port == p_to_port) { ERR_FAIL_V(ERR_ALREADY_EXISTS); } @@ -2586,7 +2586,7 @@ void VisualShaderNodeUniformRef::clear_uniforms() { } bool VisualShaderNodeUniformRef::has_uniform(const String &p_name) { - for (VisualShaderNodeUniformRef::Uniform &E : uniforms) { + for (const VisualShaderNodeUniformRef::Uniform &E : uniforms) { if (E.name == p_name) { return true; } -- cgit v1.2.3