diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp index ee20aea35d3d..a0412e91ff41 100644 --- a/core/config/project_settings.cpp +++ b/core/config/project_settings.cpp @@ -253,7 +253,7 @@ bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const { } void ProjectSettings::add_hidden_prefix(const String &p_prefix) { - ERR_FAIL_COND_MSG(hidden_prefixes.find(p_prefix) > -1, vformat("Hidden prefix '%s' already exists.", p_prefix)); + ERR_FAIL_COND_MSG(hidden_prefixes.has(p_prefix), vformat("Hidden prefix '%s' already exists.", p_prefix)); hidden_prefixes.push_back(p_prefix); } diff --git a/core/templates/local_vector.h b/core/templates/local_vector.h index e0047e0782ad..c281d70d9285 100644 --- a/core/templates/local_vector.h +++ b/core/templates/local_vector.h @@ -264,6 +264,10 @@ class LocalVector { return -1; } + bool has(const T &p_val) const { + return find(p_val) != -1; + } + template void sort_custom() { U len = count; diff --git a/drivers/vulkan/rendering_device_driver_vulkan.cpp b/drivers/vulkan/rendering_device_driver_vulkan.cpp index 339d0782bfa9..131e0e4a8a40 100644 --- a/drivers/vulkan/rendering_device_driver_vulkan.cpp +++ b/drivers/vulkan/rendering_device_driver_vulkan.cpp @@ -2603,7 +2603,7 @@ Error RenderingDeviceDriverVulkan::swap_chain_resize(CommandQueueID p_cmd_queue, break; } - bool present_mode_available = present_modes.find(present_mode) >= 0; + bool present_mode_available = present_modes.has(present_mode); if (present_mode_available) { print_verbose("Using present mode: " + present_mode_name); } else { diff --git a/editor/editor_property_name_processor.cpp b/editor/editor_property_name_processor.cpp index 1318b84d605e..a00b50c191fd 100644 --- a/editor/editor_property_name_processor.cpp +++ b/editor/editor_property_name_processor.cpp @@ -75,7 +75,7 @@ String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const Vector parts = p_name.split("_", false); for (int i = 0; i < parts.size(); i++) { // Articles/conjunctions/prepositions which should only be capitalized when not at beginning and end. - if (i > 0 && i + 1 < parts.size() && stop_words.find(parts[i]) != -1) { + if (i > 0 && i + 1 < parts.size() && stop_words.has(parts[i])) { continue; } HashMap::ConstIterator remap = capitalize_string_remaps.find(parts[i]); diff --git a/editor/multi_node_edit.h b/editor/multi_node_edit.h index 000d41c4c1fe..32fe7402fd71 100644 --- a/editor/multi_node_edit.h +++ b/editor/multi_node_edit.h @@ -73,7 +73,7 @@ class MultiNodeEdit : public RefCounted { return false; } for (int i = 0; i < get_node_count(); i++) { - if (nodes.find(p_other->get_node(i)) == -1) { + if (!nodes.has(p_other->get_node(i))) { return false; } } diff --git a/modules/csg/csg.cpp b/modules/csg/csg.cpp index 878664bb9c0d..cec03b7246de 100644 --- a/modules/csg/csg.cpp +++ b/modules/csg/csg.cpp @@ -1098,7 +1098,7 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s }; // Check if edge has already been processed. - if (processed_edges.find(edge_points_and_uvs) != -1) { + if (processed_edges.has(edge_points_and_uvs)) { continue; } diff --git a/modules/navigation/3d/godot_navigation_server_3d.cpp b/modules/navigation/3d/godot_navigation_server_3d.cpp index 61a128e00479..6cbfd930882f 100644 --- a/modules/navigation/3d/godot_navigation_server_3d.cpp +++ b/modules/navigation/3d/godot_navigation_server_3d.cpp @@ -136,7 +136,7 @@ bool GodotNavigationServer3D::map_is_active(RID p_map) const { NavMap *map = map_owner.get_or_null(p_map); ERR_FAIL_NULL_V(map, false); - return active_maps.find(map) >= 0; + return active_maps.has(map); } COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) { diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index a3f2ee2e615e..dfbc92a91948 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -734,7 +734,7 @@ void NavMap::remove_link(NavLink *p_link) { } bool NavMap::has_agent(NavAgent *agent) const { - return (agents.find(agent) >= 0); + return agents.has(agent); } void NavMap::add_agent(NavAgent *agent) { @@ -754,7 +754,7 @@ void NavMap::remove_agent(NavAgent *agent) { } bool NavMap::has_obstacle(NavObstacle *obstacle) const { - return (obstacles.find(obstacle) >= 0); + return obstacles.has(obstacle); } void NavMap::add_obstacle(NavObstacle *obstacle) { diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 06cdc022133d..b8c691c6e79f 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2374,7 +2374,7 @@ void Viewport::_gui_hide_control(Control *p_control) { if (gui.key_focus == p_control) { gui_release_focus(); } - if (gui.mouse_over == p_control || gui.mouse_over_hierarchy.find(p_control) >= 0) { + if (gui.mouse_over == p_control || gui.mouse_over_hierarchy.has(p_control)) { _drop_mouse_over(p_control->get_parent_control()); } if (gui.drag_mouse_over == p_control) { @@ -2394,7 +2394,7 @@ void Viewport::_gui_remove_control(Control *p_control) { if (gui.key_focus == p_control) { gui.key_focus = nullptr; } - if (gui.mouse_over == p_control || gui.mouse_over_hierarchy.find(p_control) >= 0) { + if (gui.mouse_over == p_control || gui.mouse_over_hierarchy.has(p_control)) { _drop_mouse_over(p_control->get_parent_control()); } if (gui.drag_mouse_over == p_control) { diff --git a/servers/physics_3d/godot_shape_3d.cpp b/servers/physics_3d/godot_shape_3d.cpp index 6eb983d5e0c8..70b6bcf19ed9 100644 --- a/servers/physics_3d/godot_shape_3d.cpp +++ b/servers/physics_3d/godot_shape_3d.cpp @@ -1133,7 +1133,7 @@ void GodotConvexPolygonShape3D::_setup(const Vector &p_vertices) { max_support = s; } } - if (extreme_vertices.find(best_vertex) == -1) + if (!extreme_vertices.has(best_vertex)) extreme_vertices.push_back(best_vertex); } } diff --git a/servers/physics_3d/godot_soft_body_3d.cpp b/servers/physics_3d/godot_soft_body_3d.cpp index e62197732679..fd9141f46e9d 100644 --- a/servers/physics_3d/godot_soft_body_3d.cpp +++ b/servers/physics_3d/godot_soft_body_3d.cpp @@ -626,11 +626,11 @@ void GodotSoftBody3D::generate_bending_constraints(int p_distance) { for (Link &link : links) { const int ia = (int)(link.n[0] - &nodes[0]); const int ib = (int)(link.n[1] - &nodes[0]); - if (node_links[ia].find(ib) == -1) { + if (!node_links[ia].has(ib)) { node_links[ia].push_back(ib); } - if (node_links[ib].find(ia) == -1) { + if (!node_links[ib].has(ia)) { node_links[ib].push_back(ia); } } diff --git a/tests/core/templates/test_local_vector.h b/tests/core/templates/test_local_vector.h index 2873a9a028ee..c9544c625bea 100644 --- a/tests/core/templates/test_local_vector.h +++ b/tests/core/templates/test_local_vector.h @@ -63,7 +63,7 @@ TEST_CASE("[LocalVector] Push Back.") { CHECK(vector[4] == 4); } -TEST_CASE("[LocalVector] Find.") { +TEST_CASE("[LocalVector] Find, has.") { LocalVector vector; vector.push_back(3); vector.push_back(1); @@ -85,6 +85,15 @@ TEST_CASE("[LocalVector] Find.") { CHECK(vector.find(-1) == -1); CHECK(vector.find(5) == -1); + + CHECK(vector.has(0)); + CHECK(vector.has(1)); + CHECK(vector.has(2)); + CHECK(vector.has(3)); + CHECK(vector.has(4)); + + CHECK(!vector.has(-1)); + CHECK(!vector.has(5)); } TEST_CASE("[LocalVector] Remove.") {