Skip to content

Commit

Permalink
Add const references detected by clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubonnek committed Dec 16, 2023
1 parent 2d0ee20 commit a3cb1b0
Show file tree
Hide file tree
Showing 57 changed files with 120 additions and 120 deletions.
2 changes: 1 addition & 1 deletion core/debugger/engine_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void EngineDebugger::initialize(const String &p_uri, bool p_skip_breakpoints, Ve
singleton_script_debugger->set_skip_breakpoints(p_skip_breakpoints);

for (int i = 0; i < p_breakpoints.size(); i++) {
String bp = p_breakpoints[i];
const String &bp = p_breakpoints[i];
int sp = bp.rfind(":");
ERR_CONTINUE_MSG(sp == -1, "Invalid breakpoint: '" + bp + "', expected file:line format.");

Expand Down
2 changes: 1 addition & 1 deletion core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ void Input::add_joy_mapping(String p_mapping, bool p_update_existing) {
parse_mapping(p_mapping);
if (p_update_existing) {
Vector<String> entry = p_mapping.split(",");
String uid = entry[0];
const String &uid = entry[0];
for (KeyValue<int, Joypad> &E : joy_names) {
Joypad &joy = E.value;
if (joy.uid == uid) {
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 @@ -754,7 +754,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins_with_featur
String fullname = E.key;

Vector<String> split = fullname.split(".");
String name = split[0];
const String &name = split[0];
String override_for = split.size() > 1 ? split[1] : String();

if (!override_for.is_empty() && OS::get_singleton()->has_feature(override_for)) {
Expand All @@ -766,7 +766,7 @@ const HashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins_with_featur
String fullname = E.key;

Vector<String> split = fullname.split(".");
String name = split[0];
const String &name = split[0];
String override_for = split.size() > 1 ? split[1] : String();

if (builtins_with_overrides.has(name) && override_for.is_empty()) {
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ PackedData::PackedDir *DirAccessPack::_find_dir(String p_dir) {
}

for (int i = 0; i < paths.size(); i++) {
String p = paths[i];
const String &p = paths[i];
if (p == ".") {
continue;
} else if (p == "..") {
Expand Down
2 changes: 1 addition & 1 deletion core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) {
Array keys = p_dict.keys();
for (int i = 0; i < keys.size(); ++i) {
String encoded_key = String(keys[i]).uri_encode();
Variant value = p_dict[keys[i]];
const Variant &value = p_dict[keys[i]];
switch (value.get_type()) {
case Variant::ARRAY: {
// Repeat the key with every values
Expand Down
4 changes: 2 additions & 2 deletions core/os/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Key find_keycode(const String &p_codestr) {
return keycode;
}

String last_part = code_parts[code_parts.size() - 1];
const String &last_part = code_parts[code_parts.size() - 1];
const _KeyCodeText *kct = &_keycodes[0];

while (kct->text) {
Expand All @@ -422,7 +422,7 @@ Key find_keycode(const String &p_codestr) {
}

for (int part = 0; part < code_parts.size() - 1; part++) {
String code_part = code_parts[part];
const String &code_part = code_parts[part];
if (code_part.nocasecmp_to(find_keycode_name(Key::SHIFT)) == 0) {
keycode |= KeyModifierMask::SHIFT;
} else if (code_part.nocasecmp_to(find_keycode_name(Key::CTRL)) == 0) {
Expand Down
4 changes: 2 additions & 2 deletions core/string/ustring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4569,7 +4569,7 @@ bool String::is_valid_ip_address() const {
if (find(":") >= 0) {
Vector<String> ip = split(":");
for (int i = 0; i < ip.size(); i++) {
String n = ip[i];
const String &n = ip[i];
if (n.is_empty()) {
continue;
}
Expand All @@ -4591,7 +4591,7 @@ bool String::is_valid_ip_address() const {
return false;
}
for (int i = 0; i < ip.size(); i++) {
String n = ip[i];
const String &n = ip[i];
if (!n.is_valid_int()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/shader_gles3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void ShaderGLES3::_add_stage(const char *p_code, StageType p_stage_type) {
String text;

for (int i = 0; i < lines.size(); i++) {
String l = lines[i];
const String &l = lines[i];
bool push_chunk = false;

StageTemplate::Chunk chunk;
Expand Down
2 changes: 1 addition & 1 deletion drivers/gles3/storage/texture_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ void TextureStorage::texture_2d_layered_initialize(RID p_texture, const Vector<R
ERR_FAIL_COND(p_layered_type == RS::TEXTURE_LAYERED_CUBEMAP && p_layers.size() != 6);
ERR_FAIL_COND_MSG(p_layered_type == RS::TEXTURE_LAYERED_CUBEMAP_ARRAY, "Cubemap Arrays are not supported in the GL Compatibility backend.");

Ref<Image> image = p_layers[0];
const Ref<Image> &image = p_layers[0];
{
int valid_width = 0;
int valid_height = 0;
Expand Down
4 changes: 2 additions & 2 deletions editor/code_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ void CodeTextEditor::move_lines_up() {

for (int j = 0; j < caret_groups[i].size(); j++) {
int c = caret_groups[i][j];
Vector<int> caret_parameters = caret_group_parameters[j];
const Vector<int> &caret_parameters = caret_group_parameters[j];
text_editor->set_caret_line(caret_parameters[4] - 1, c == 0, true, 0, c);
text_editor->set_caret_column(caret_parameters[5], c == 0, c);

Expand Down Expand Up @@ -1374,7 +1374,7 @@ void CodeTextEditor::move_lines_down() {

for (int j = 0; j < caret_groups[i].size(); j++) {
int c = caret_groups[i][j];
Vector<int> caret_parameters = caret_group_parameters[j];
const Vector<int> &caret_parameters = caret_group_parameters[j];
text_editor->set_caret_line(caret_parameters[4] + 1, c == 0, true, 0, c);
text_editor->set_caret_column(caret_parameters[5], c == 0, c);

Expand Down
2 changes: 1 addition & 1 deletion editor/debugger/script_editor_debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ void ScriptEditorDebugger::_item_menu_id_pressed(int p_option) {
// Parse back the `file:line @ method()` string.
const Vector<String> file_line_number = ci->get_text(1).split("@")[0].strip_edges().split(":");
ERR_FAIL_COND_MSG(file_line_number.size() < 2, "Incorrect C++ source stack trace file:line format (please report).");
const String file = file_line_number[0];
const String &file = file_line_number[0];
const int line_number = file_line_number[1].to_int();

// Construct a GitHub repository URL and open it in the user's default web browser.
Expand Down
2 changes: 1 addition & 1 deletion editor/doc_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void DocTools::generate(BitField<GenerateFlags> p_flags) {
continue;
}

String cname = name;
const String &cname = name;
// Property setters and getters do not get exposed as individual methods.
HashSet<StringName> setters_getters;

Expand Down
4 changes: 2 additions & 2 deletions editor/editor_build_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ void EditorBuildProfileManager::_detect_classes() {
String l = f->get_line();
Vector<String> fields = l.split("::");
if (fields.size() == 4) {
String path = fields[0];
const String &path = fields[0];
DetectedFile df;
df.timestamp = fields[1].to_int();
df.md5 = fields[2];
Expand Down Expand Up @@ -597,7 +597,7 @@ void EditorBuildProfileManager::_fill_classes_from(TreeItem *p_parent, const Str
TreeItem *class_item = class_list->create_item(p_parent);
class_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
class_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_class));
String text = p_class;
const String &text = p_class;

bool disabled = edited->is_class_disabled(p_class);
if (disabled) {
Expand Down
4 changes: 2 additions & 2 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void EditorFileSystem::_scan_filesystem() {
if (l.begins_with("::")) {
Vector<String> split = l.split("::");
ERR_CONTINUE(split.size() != 3);
String name = split[1];
const String &name = split[1];

cpath = name;

Expand Down Expand Up @@ -289,7 +289,7 @@ void EditorFileSystem::_scan_filesystem() {
if (deps.length()) {
Vector<String> dp = deps.split("<>");
for (int i = 0; i < dp.size(); i++) {
String path = dp[i];
const String &path = dp[i];
fc.deps.push_back(path);
}
}
Expand Down
8 changes: 4 additions & 4 deletions editor/editor_help.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2867,10 +2867,10 @@ void EditorHelpTooltip::parse_tooltip(const String &p_text) {
PackedStringArray slices = p_text.split("|", true, 3);
ERR_FAIL_COND_MSG(slices.size() < 4, "Invalid tooltip formatting. The expect string should be formatted as 'type|class|property|args'.");

String type = slices[0];
String class_name = slices[1];
String property_name = slices[2];
String property_args = slices[3];
const String &type = slices[0];
const String &class_name = slices[1];
const String &property_name = slices[2];
const String &property_args = slices[3];

String title;
String description;
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3018,7 +3018,7 @@ void EditorInspector::update_tree() {

Vector<String> components = path.split("/");
for (int i = 0; i < components.size(); i++) {
String component = components[i];
const String &component = components[i];
acc_path += (i > 0) ? "/" + component : component;

if (!vbox_per_path[root_vbox].has(acc_path)) {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Vector<Ref<Texture2D>> EditorInterface::make_mesh_previews(const Vector<Ref<Mesh
Vector<Ref<Texture2D>> textures;

for (int i = 0; i < p_meshes.size(); i++) {
Ref<Mesh> mesh = p_meshes[i];
const Ref<Mesh> &mesh = p_meshes[i];
if (!mesh.is_valid()) {
textures.push_back(Ref<Texture2D>());
continue;
Expand Down
14 changes: 7 additions & 7 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vecto
Vector<RBSet<int>> index_sets;
HashMap<String, int> scene_name_to_set_index;
for (int i = 0; i < r_filenames.size(); i++) {
String scene_name = r_filenames[i];
const String &scene_name = r_filenames[i];
if (!scene_name_to_set_index.has(scene_name)) {
index_sets.append(RBSet<int>());
scene_name_to_set_index.insert(r_filenames[i], index_sets.size() - 1);
Expand Down Expand Up @@ -232,7 +232,7 @@ void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vecto
if (E->get() == F) {
continue;
}
String other_scene_name = r_filenames[F];
const String &other_scene_name = r_filenames[F];
if (other_scene_name == scene_name) {
duplicate_found = true;
break;
Expand Down Expand Up @@ -4197,7 +4197,7 @@ void EditorNode::_quick_opened() {

bool open_scene_dialog = quick_open->get_base_type() == "PackedScene";
for (int i = 0; i < files.size(); i++) {
String res_path = files[i];
const String &res_path = files[i];
if (open_scene_dialog || ClassDB::is_parent_class(ResourceLoader::get_resource_type(res_path), "PackedScene")) {
open_request(res_path);
} else {
Expand Down Expand Up @@ -4595,8 +4595,8 @@ String EditorNode::_get_system_info() const {
}
graphics += rendering_device_name;
if (video_adapter_driver_info.size() == 2) { // This vector is always either of length 0 or 2.
String vad_name = video_adapter_driver_info[0];
String vad_version = video_adapter_driver_info[1]; // Version could be potentially empty on Linux/BSD.
const String &vad_name = video_adapter_driver_info[0];
const String &vad_version = video_adapter_driver_info[1]; // Version could be potentially empty on Linux/BSD.
if (!vad_version.is_empty()) {
graphics += vformat(" (%s; %s)", vad_name, vad_version);
} else {
Expand Down Expand Up @@ -5187,7 +5187,7 @@ void EditorNode::_load_docks_from_config(Ref<ConfigFile> p_layout, const String
Vector<String> names = String(p_layout->get_value(p_section, "dock_" + itos(i + 1))).split(",");

for (int j = names.size() - 1; j >= 0; j--) {
String name = names[j];
const String &name = names[j];

// FIXME: Find it, in a horribly inefficient way.
int atidx = -1;
Expand Down Expand Up @@ -6003,7 +6003,7 @@ void EditorNode::_add_dropped_files_recursive(const Vector<String> &p_files, Str
ERR_FAIL_COND(dir.is_null());

for (int i = 0; i < p_files.size(); i++) {
String from = p_files[i];
const String &from = p_files[i];
String to = to_path.path_join(from.get_file());

if (dir->dir_exists(from)) {
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_plugin_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void EditorPluginSettings::update_plugins() {
for (int i = 0; i < plugins.size(); i++) {
Ref<ConfigFile> cf;
cf.instantiate();
const String path = plugins[i];
const String &path = plugins[i];

Error err2 = cf->load(path);

Expand Down
4 changes: 2 additions & 2 deletions editor/editor_properties_array_dict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const {
Vector<String> files = drag_data["files"];

for (int i = 0; i < files.size(); i++) {
String file = files[i];
const String &file = files[i];
String ftype = EditorFileSystem::get_singleton()->get_file_type(file);

for (int j = 0; j < allowed_type.get_slice_count(","); j++) {
Expand Down Expand Up @@ -510,7 +510,7 @@ void EditorPropertyArray::drop_data_fw(const Point2 &p_point, const Variant &p_d

// Loop the file array and add to existing array.
for (int i = 0; i < files.size(); i++) {
String file = files[i];
const String &file = files[i];

Ref<Resource> res = ResourceLoader::load(file);
if (res.is_valid()) {
Expand Down
8 changes: 4 additions & 4 deletions editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ void EditorExportPlatform::_edit_files_with_filter(Ref<DirAccess> &da, const Vec
da->list_dir_end();

for (int i = 0; i < dirs.size(); ++i) {
String dir = dirs[i];
const String &dir = dirs[i];
if (dir.begins_with(".")) {
continue;
}
Expand Down Expand Up @@ -1096,7 +1096,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
Vector<String> fields = l.split("::");
if (fields.size() == 4) {
FileExportCache fec;
String path = fields[0];
const String &path = fields[0];
fec.source_md5 = fields[1].strip_edges();
fec.source_modified_time = fields[2].strip_edges().to_int();
fec.saved_path = fields[3];
Expand Down Expand Up @@ -1364,8 +1364,8 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> &
if (path_remaps.size()) {
if (true) { //new remap mode, use always as it's friendlier with multiple .pck exports
for (int i = 0; i < path_remaps.size(); i += 2) {
String from = path_remaps[i];
String to = path_remaps[i + 1];
const String &from = path_remaps[i];
const String &to = path_remaps[i + 1];
String remap_file = "[remap]\n\npath=\"" + to.c_escape() + "\"\n";
CharString utf8 = remap_file.utf8();
Vector<uint8_t> new_file;
Expand Down
Loading

0 comments on commit a3cb1b0

Please sign in to comment.