From d0bd0fd0777a942ae47827967b4aa88c178e0517 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 22 Jul 2023 14:32:39 -0600 Subject: [PATCH] improve duplicate to linear complexity --- duplicate.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/duplicate.cc b/duplicate.cc index 37d61d271..2e6df72da 100644 --- a/duplicate.cc +++ b/duplicate.cc @@ -127,17 +127,16 @@ void DuplicateFilter::process() } } - // Do all the deletes with iterators to avoid repeated - // searches in waypt_del(Waypoint*). - auto it = global_waypoint_list->begin(); - while (it != global_waypoint_list->end()) { - auto wpt = *it; + // For lineary complexity build a new list from the points we keep. + WaypointList oldlist; + waypt_swap(oldlist); + + for (Waypoint* wpt : qAsConst(oldlist)) { if (wpt->extra_data != nullptr) { - it = global_waypoint_list->waypt_del(it); delete wpt; } else { wpt->extra_data = nullptr; - ++it; + waypt_add(wpt); } } }