From 8fce9378cc4d9d10a2910ad12041a03a0c46a723 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sat, 5 Dec 2015 19:52:12 -0800 Subject: [PATCH] Extract entry list truncation. --- firmware/application/app_ais.cpp | 10 +++++++--- firmware/application/app_ais.hpp | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/firmware/application/app_ais.cpp b/firmware/application/app_ais.cpp index ebdbc486..75213c5a 100644 --- a/firmware/application/app_ais.cpp +++ b/firmware/application/app_ais.cpp @@ -349,6 +349,12 @@ void AISView::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) { const auto source_id = packet.source_id(); 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); } else { recent.emplace_front(source_id); - while(recent.size() > 64) { - recent.pop_back(); - } + truncate_entries(); } auto& entry = recent.front(); diff --git a/firmware/application/app_ais.hpp b/firmware/application/app_ais.hpp index 0bc82877..6979770a 100644 --- a/firmware/application/app_ais.hpp +++ b/firmware/application/app_ais.hpp @@ -173,6 +173,8 @@ private: void on_packet(const baseband::ais::Packet& packet); + void truncate_entries(); + RecentEntries::iterator selected_entry(); void advance(const int32_t amount);