Skip to content

Commit

Permalink
improve duplicate to linear complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
tsteven4 committed Jul 22, 2023
1 parent 2d2268a commit d0bd0fd
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions duplicate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit d0bd0fd

Please sign in to comment.