diff --git a/planning/behavior_path_planner/src/utils/path_safety_checker/objects_filtering.cpp b/planning/behavior_path_planner/src/utils/path_safety_checker/objects_filtering.cpp index d86aa88ae050e..e80c23fb5000c 100644 --- a/planning/behavior_path_planner/src/utils/path_safety_checker/objects_filtering.cpp +++ b/planning/behavior_path_planner/src/utils/path_safety_checker/objects_filtering.cpp @@ -105,11 +105,10 @@ void filterObjectsByPosition( return (-backward_distance < dist_ego_to_obj && dist_ego_to_obj < forward_distance); }; - // Create a new container to hold the filtered objects - PredictedObjects filtered = filterObjects(objects, position_filter); - - // Replace the original objects with the filtered list - objects.objects = std::move(filtered.objects); + // Erase objects based on filtered list + objects.objects.erase( + std::partition(objects.objects.begin(), objects.objects.end(), position_filter), + objects.objects.end()); } void filterObjectsByClass( @@ -119,10 +118,10 @@ void filterObjectsByClass( return isTargetObjectType(object, target_object_types); }; - PredictedObjects filtered_objects = filterObjects(objects, object_class_filter); - - // Replace the original objects with the filtered list - objects = std::move(filtered_objects); + // Erase objects based on filtered list + objects.objects.erase( + std::partition(objects.objects.begin(), objects.objects.end(), object_class_filter), + objects.objects.end()); } std::pair, std::vector> separateObjectIndicesByLanelets(