Vectors: Use clear() and has().

Use clear() instead of resize(0).

Use has() instead of "find(p_val) != -1".
This commit is contained in:
Anilforextra 2022-02-02 00:04:13 +05:45
parent ea12094f19
commit fc27636999
36 changed files with 62 additions and 64 deletions

View file

@ -3289,7 +3289,7 @@ AnimationTrackEditGroup::AnimationTrackEditGroup() {
//////////////////////////////////////
void AnimationTrackEditor::add_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin) {
if (track_edit_plugins.find(p_plugin) != -1) {
if (track_edit_plugins.has(p_plugin)) {
return;
}
track_edit_plugins.push_back(p_plugin);

View file

@ -467,7 +467,7 @@ void CreateDialog::select_type(const String &p_type) {
}
favorite->set_disabled(false);
favorite->set_pressed(favorite_list.find(p_type) != -1);
favorite->set_pressed(favorite_list.has(p_type));
get_ok_button()->set_disabled(false);
}
@ -539,12 +539,12 @@ void CreateDialog::_favorite_toggled() {
String name = item->get_text(0);
if (favorite_list.find(name) == -1) {
favorite_list.push_back(name);
favorite->set_pressed(true);
} else {
if (favorite_list.has(name)) {
favorite_list.erase(name);
favorite->set_pressed(false);
} else {
favorite_list.push_back(name);
favorite->set_pressed(true);
}
_save_and_update_favorite_list();

View file

@ -534,11 +534,11 @@ void DocTools::generate(bool p_basic_types) {
Vector<Error> errs = ClassDB::get_method_error_return_values(name, E.name);
if (errs.size()) {
if (errs.find(OK) == -1) {
if (!errs.has(OK)) {
errs.insert(0, OK);
}
for (int i = 0; i < errs.size(); i++) {
if (method.errors_returned.find(errs[i]) == -1) {
if (!method.errors_returned.has(errs[i])) {
method.errors_returned.push_back(errs[i]);
}
}

View file

@ -1525,7 +1525,7 @@ void EditorExport::remove_export_preset(int p_idx) {
}
void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) {
if (export_plugins.find(p_plugin) == -1) {
if (!export_plugins.has(p_plugin)) {
export_plugins.push_back(p_plugin);
}
}

View file

@ -3725,7 +3725,7 @@ void EditorNode::_show_messages() {
void EditorNode::_add_to_recent_scenes(const String &p_scene) {
Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scenes", Array());
if (rc.find(p_scene) != -1) {
if (rc.has(p_scene)) {
rc.erase(p_scene);
}
rc.push_front(p_scene);

View file

@ -369,7 +369,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) {
// Skip locales which we can't render properly (see above comment).
// Test against language code without regional variants (e.g. ur_PK).
String lang_code = locale.get_slice("_", 0);
if (locales_to_skip.find(lang_code) != -1) {
if (locales_to_skip.has(lang_code)) {
continue;
}

View file

@ -1801,7 +1801,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected
// Add the files from favorites.
Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < p_selected.size(); i++) {
if (favorites.find(p_selected[i]) == -1) {
if (!favorites.has(p_selected[i])) {
favorites.push_back(p_selected[i]);
}
}
@ -2324,7 +2324,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data,
Vector<String> fnames = drag_data["files"];
Vector<String> favorites = EditorSettings::get_singleton()->get_favorites();
for (int i = 0; i < fnames.size(); i++) {
if (favorites.find(fnames[i]) == -1) {
if (!favorites.has(fnames[i])) {
favorites.push_back(fnames[i]);
}
}

View file

@ -517,7 +517,7 @@ bool ResourceImporterLayeredTexture::are_import_settings_valid(const String &p_p
String setting_path = "rendering/textures/vram_compression/import_" + String(compression_formats[index]);
bool test = ProjectSettings::get_singleton()->get(setting_path);
if (test) {
if (formats_imported.find(compression_formats[index]) == -1) {
if (!formats_imported.has(compression_formats[index])) {
valid = false;
break;
}

View file

@ -628,7 +628,7 @@ bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) co
String setting_path = "rendering/textures/vram_compression/import_" + String(compression_formats[index]);
bool test = ProjectSettings::get_singleton()->get(setting_path);
if (test) {
if (formats_imported.find(compression_formats[index]) == -1) {
if (!formats_imported.has(compression_formats[index])) {
valid = false;
break;
}

View file

@ -447,7 +447,7 @@ static bool _find_owners(EditorFileSystemDirectory *efsd, const String &p_path)
for (int i = 0; i < efsd->get_file_count(); i++) {
Vector<String> deps = efsd->get_file_deps(i);
if (deps.find(p_path) != -1) {
if (deps.has(p_path)) {
return true;
}
}

View file

@ -180,7 +180,7 @@ void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEven
selected_point = -1;
for (int i = 0; i < points.size(); i++) {
if (making_triangle.find(i) != -1) {
if (making_triangle.has(i)) {
continue;
}

View file

@ -755,7 +755,7 @@ void AnimationNodeStateMachineEditor::_state_machine_draw() {
//now scroll it to draw
state_machine_draw->draw_style_box(sb, nr.node);
if (playing && (blend_from == name || current == name || travel_path.find(name) != -1)) {
if (playing && (blend_from == name || current == name || travel_path.has(name))) {
state_machine_draw->draw_style_box(playing_overlay, nr.node);
}

View file

@ -473,7 +473,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
uv_move_current = uv_mode;
if (uv_move_current == UV_MODE_CREATE) {
if (!uv_create) {
points_prev.resize(0);
points_prev.clear();
Vector2 tuv = mtx.affine_inverse().xform(snap_point(mb->get_position()));
points_prev.push_back(tuv);
uv_create_to = tuv;
@ -682,7 +682,7 @@ void Polygon2DEditor::_uv_input(const Ref<InputEvent> &p_input) {
}
polygon_create.clear();
} else if (polygon_create.find(closest) == -1) {
} else if (!polygon_create.has(closest)) {
//add temporarily if not exists
polygon_create.push_back(closest);
}

View file

@ -3486,7 +3486,7 @@ void ScriptEditor::_open_script_request(const String &p_path) {
void ScriptEditor::register_syntax_highlighter(const Ref<EditorSyntaxHighlighter> &p_syntax_highlighter) {
ERR_FAIL_COND(p_syntax_highlighter.is_null());
if (syntax_highlighters.find(p_syntax_highlighter) == -1) {
if (!syntax_highlighters.has(p_syntax_highlighter)) {
syntax_highlighters.push_back(p_syntax_highlighter);
}
}

View file

@ -1030,7 +1030,7 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) {
}
void VisualShaderEditor::add_plugin(const Ref<VisualShaderNodePlugin> &p_plugin) {
if (plugins.find(p_plugin) != -1) {
if (plugins.has(p_plugin)) {
return;
}
plugins.push_back(p_plugin);

View file

@ -185,7 +185,7 @@ void PropertySelector::_update_search() {
continue;
}
if (type_filter.size() && type_filter.find(E.type) == -1) {
if (type_filter.size() && !type_filter.has(E.type)) {
continue;
}

View file

@ -1723,7 +1723,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V
Node *validate = new_parent;
while (validate) {
ERR_FAIL_COND_MSG(p_nodes.find(validate) != -1, "Selection changed at some point. Can't reparent.");
ERR_FAIL_COND_MSG(p_nodes.has(validate), "Selection changed at some point. Can't reparent.");
validate = validate->get_parent();
}