Extract entry list truncation.

This commit is contained in:
Jared Boone 2015-12-05 19:52:12 -08:00
parent 9791d64b50
commit 8fce9378cc
2 changed files with 9 additions and 3 deletions

View File

@ -349,6 +349,12 @@ void AISView::on_hide() {
View::on_hide(); View::on_hide();
} }
void AISView::truncate_entries() {
while(recent.size() > 64) {
recent.pop_back();
}
}
void AISView::on_packet(const baseband::ais::Packet& packet) { void AISView::on_packet(const baseband::ais::Packet& packet) {
const auto source_id = packet.source_id(); const auto source_id = packet.source_id();
auto matching_recent = std::find_if(recent.begin(), recent.end(), auto matching_recent = std::find_if(recent.begin(), recent.end(),
@ -360,9 +366,7 @@ void AISView::on_packet(const baseband::ais::Packet& packet) {
recent.erase(matching_recent); recent.erase(matching_recent);
} else { } else {
recent.emplace_front(source_id); recent.emplace_front(source_id);
while(recent.size() > 64) { truncate_entries();
recent.pop_back();
}
} }
auto& entry = recent.front(); auto& entry = recent.front();

View File

@ -173,6 +173,8 @@ private:
void on_packet(const baseband::ais::Packet& packet); void on_packet(const baseband::ais::Packet& packet);
void truncate_entries();
RecentEntries::iterator selected_entry(); RecentEntries::iterator selected_entry();
void advance(const int32_t amount); void advance(const int32_t amount);