Merge pull request #91621 from AThousandShips/localvector_has

[Core] Add `LocalVector::has` for convenience
This commit is contained in:
Rémi Verschelde 2024-05-06 22:33:45 +02:00
commit 7cdad33311
No known key found for this signature in database
GPG key ID: C3336907360768E1
12 changed files with 27 additions and 14 deletions

View file

@ -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);
}

View file

@ -264,6 +264,10 @@ public:
return -1;
}
bool has(const T &p_val) const {
return find(p_val) != -1;
}
template <typename C>
void sort_custom() {
U len = count;

View file

@ -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 {

View file

@ -75,7 +75,7 @@ String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const
Vector<String> 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<String, String>::ConstIterator remap = capitalize_string_remaps.find(parts[i]);

View file

@ -73,7 +73,7 @@ public:
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;
}
}

View file

@ -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;
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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) {

View file

@ -1133,7 +1133,7 @@ void GodotConvexPolygonShape3D::_setup(const Vector<Vector3> &p_vertices) {
max_support = s;
}
}
if (extreme_vertices.find(best_vertex) == -1)
if (!extreme_vertices.has(best_vertex))
extreme_vertices.push_back(best_vertex);
}
}

View file

@ -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);
}
}

View file

@ -63,7 +63,7 @@ TEST_CASE("[LocalVector] Push Back.") {
CHECK(vector[4] == 4);
}
TEST_CASE("[LocalVector] Find.") {
TEST_CASE("[LocalVector] Find, has.") {
LocalVector<int> 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.") {