Add LocalVector.erase_unordered, mimicking erase but with remove_at_unordered, to remove duplicate logic.

`erase_unordered` should be preferred over `erase` where order is not important, for its performance benefits.

Co-authored-by: smix8 <smix8@users.noreply.github.com>
This commit is contained in:
Lukas Tenbrink
2025-01-02 16:32:54 +01:00
parent e585e6a3eb
commit ccdc5862e9
4 changed files with 37 additions and 33 deletions

View File

@@ -235,9 +235,7 @@ void NavMap3D::add_region(NavRegion3D *p_region) {
}
void NavMap3D::remove_region(NavRegion3D *p_region) {
int64_t region_index = regions.find(p_region);
if (region_index >= 0) {
regions.remove_at_unordered(region_index);
if (regions.erase_unordered(p_region)) {
iteration_dirty = true;
}
}
@@ -248,9 +246,7 @@ void NavMap3D::add_link(NavLink3D *p_link) {
}
void NavMap3D::remove_link(NavLink3D *p_link) {
int64_t link_index = links.find(p_link);
if (link_index >= 0) {
links.remove_at_unordered(link_index);
if (links.erase_unordered(p_link)) {
iteration_dirty = true;
}
}
@@ -268,9 +264,7 @@ void NavMap3D::add_agent(NavAgent3D *agent) {
void NavMap3D::remove_agent(NavAgent3D *agent) {
remove_agent_as_controlled(agent);
int64_t agent_index = agents.find(agent);
if (agent_index >= 0) {
agents.remove_at_unordered(agent_index);
if (agents.erase_unordered(agent)) {
agents_dirty = true;
}
}
@@ -292,9 +286,7 @@ void NavMap3D::add_obstacle(NavObstacle3D *obstacle) {
}
void NavMap3D::remove_obstacle(NavObstacle3D *obstacle) {
int64_t obstacle_index = obstacles.find(obstacle);
if (obstacle_index >= 0) {
obstacles.remove_at_unordered(obstacle_index);
if (obstacles.erase_unordered(obstacle)) {
obstacles_dirty = true;
}
}
@@ -323,14 +315,10 @@ void NavMap3D::set_agent_as_controlled(NavAgent3D *agent) {
}
void NavMap3D::remove_agent_as_controlled(NavAgent3D *agent) {
int64_t agent_3d_index = active_3d_avoidance_agents.find(agent);
if (agent_3d_index >= 0) {
active_3d_avoidance_agents.remove_at_unordered(agent_3d_index);
if (active_3d_avoidance_agents.erase_unordered(agent)) {
agents_dirty = true;
}
int64_t agent_2d_index = active_2d_avoidance_agents.find(agent);
if (agent_2d_index >= 0) {
active_2d_avoidance_agents.remove_at_unordered(agent_2d_index);
if (active_2d_avoidance_agents.erase_unordered(agent)) {
agents_dirty = true;
}
}