Skip to content

Commit 7cdad33

Browse files
committed
Merge pull request godotengine#91621 from AThousandShips/localvector_has
[Core] Add `LocalVector::has` for convenience
2 parents 5c7d2d6 + 86de59d commit 7cdad33

File tree

12 files changed

+27
-14
lines changed

12 files changed

+27
-14
lines changed

core/config/project_settings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ bool ProjectSettings::get_ignore_value_in_docs(const String &p_name) const {
253253
}
254254

255255
void ProjectSettings::add_hidden_prefix(const String &p_prefix) {
256-
ERR_FAIL_COND_MSG(hidden_prefixes.find(p_prefix) > -1, vformat("Hidden prefix '%s' already exists.", p_prefix));
256+
ERR_FAIL_COND_MSG(hidden_prefixes.has(p_prefix), vformat("Hidden prefix '%s' already exists.", p_prefix));
257257
hidden_prefixes.push_back(p_prefix);
258258
}
259259

core/templates/local_vector.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ class LocalVector {
264264
return -1;
265265
}
266266

267+
bool has(const T &p_val) const {
268+
return find(p_val) != -1;
269+
}
270+
267271
template <typename C>
268272
void sort_custom() {
269273
U len = count;

drivers/vulkan/rendering_device_driver_vulkan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ Error RenderingDeviceDriverVulkan::swap_chain_resize(CommandQueueID p_cmd_queue,
26032603
break;
26042604
}
26052605

2606-
bool present_mode_available = present_modes.find(present_mode) >= 0;
2606+
bool present_mode_available = present_modes.has(present_mode);
26072607
if (present_mode_available) {
26082608
print_verbose("Using present mode: " + present_mode_name);
26092609
} else {

editor/editor_property_name_processor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ String EditorPropertyNameProcessor::_capitalize_name(const String &p_name) const
7575
Vector<String> parts = p_name.split("_", false);
7676
for (int i = 0; i < parts.size(); i++) {
7777
// Articles/conjunctions/prepositions which should only be capitalized when not at beginning and end.
78-
if (i > 0 && i + 1 < parts.size() && stop_words.find(parts[i]) != -1) {
78+
if (i > 0 && i + 1 < parts.size() && stop_words.has(parts[i])) {
7979
continue;
8080
}
8181
HashMap<String, String>::ConstIterator remap = capitalize_string_remaps.find(parts[i]);

editor/multi_node_edit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class MultiNodeEdit : public RefCounted {
7373
return false;
7474
}
7575
for (int i = 0; i < get_node_count(); i++) {
76-
if (nodes.find(p_other->get_node(i)) == -1) {
76+
if (!nodes.has(p_other->get_node(i))) {
7777
return false;
7878
}
7979
}

modules/csg/csg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ void CSGBrushOperation::Build2DFaces::_find_edge_intersections(const Vector2 p_s
10981098
};
10991099

11001100
// Check if edge has already been processed.
1101-
if (processed_edges.find(edge_points_and_uvs) != -1) {
1101+
if (processed_edges.has(edge_points_and_uvs)) {
11021102
continue;
11031103
}
11041104

modules/navigation/3d/godot_navigation_server_3d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bool GodotNavigationServer3D::map_is_active(RID p_map) const {
136136
NavMap *map = map_owner.get_or_null(p_map);
137137
ERR_FAIL_NULL_V(map, false);
138138

139-
return active_maps.find(map) >= 0;
139+
return active_maps.has(map);
140140
}
141141

142142
COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) {

modules/navigation/nav_map.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ void NavMap::remove_link(NavLink *p_link) {
734734
}
735735

736736
bool NavMap::has_agent(NavAgent *agent) const {
737-
return (agents.find(agent) >= 0);
737+
return agents.has(agent);
738738
}
739739

740740
void NavMap::add_agent(NavAgent *agent) {
@@ -754,7 +754,7 @@ void NavMap::remove_agent(NavAgent *agent) {
754754
}
755755

756756
bool NavMap::has_obstacle(NavObstacle *obstacle) const {
757-
return (obstacles.find(obstacle) >= 0);
757+
return obstacles.has(obstacle);
758758
}
759759

760760
void NavMap::add_obstacle(NavObstacle *obstacle) {

scene/main/viewport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ void Viewport::_gui_hide_control(Control *p_control) {
23742374
if (gui.key_focus == p_control) {
23752375
gui_release_focus();
23762376
}
2377-
if (gui.mouse_over == p_control || gui.mouse_over_hierarchy.find(p_control) >= 0) {
2377+
if (gui.mouse_over == p_control || gui.mouse_over_hierarchy.has(p_control)) {
23782378
_drop_mouse_over(p_control->get_parent_control());
23792379
}
23802380
if (gui.drag_mouse_over == p_control) {
@@ -2394,7 +2394,7 @@ void Viewport::_gui_remove_control(Control *p_control) {
23942394
if (gui.key_focus == p_control) {
23952395
gui.key_focus = nullptr;
23962396
}
2397-
if (gui.mouse_over == p_control || gui.mouse_over_hierarchy.find(p_control) >= 0) {
2397+
if (gui.mouse_over == p_control || gui.mouse_over_hierarchy.has(p_control)) {
23982398
_drop_mouse_over(p_control->get_parent_control());
23992399
}
24002400
if (gui.drag_mouse_over == p_control) {

servers/physics_3d/godot_shape_3d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ void GodotConvexPolygonShape3D::_setup(const Vector<Vector3> &p_vertices) {
11331133
max_support = s;
11341134
}
11351135
}
1136-
if (extreme_vertices.find(best_vertex) == -1)
1136+
if (!extreme_vertices.has(best_vertex))
11371137
extreme_vertices.push_back(best_vertex);
11381138
}
11391139
}

0 commit comments

Comments
 (0)