From f7e2cff004365f60cd26c518de4130f9281f859c Mon Sep 17 00:00:00 2001 From: Jonathan Naylor Date: Wed, 6 Apr 2016 17:24:14 +0100 Subject: [PATCH] Use the STL find function instead of an iterator. --- DMRControl.cpp | 19 +++++-------------- DMRSlot.cpp | 8 ++------ 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/DMRControl.cpp b/DMRControl.cpp index beee854..8e89e6f 100644 --- a/DMRControl.cpp +++ b/DMRControl.cpp @@ -18,6 +18,7 @@ #include #include +#include CDMRControl::CDMRControl(unsigned int id, unsigned int colorCode, bool selfOnly, const std::vector& prefixes, unsigned int timeout, CModem* modem, CDMRIPSC* network, IDisplay* display, bool duplex) : m_id(id), @@ -71,22 +72,12 @@ bool CDMRControl::processWakeup(const unsigned char* data) return false; } - bool found = false; - - if (m_prefixes.size() == 0U) - found = true; - - for (std::vector::const_iterator it = m_prefixes.begin(); it != m_prefixes.end(); ++it) { - if (prefix == *it) { - found = true; - break; + if (m_prefixes.size() > 0U) { + if (std::find(m_prefixes.begin(), m_prefixes.end(), prefix) == m_prefixes.end()) { + LogMessage("Invalid CSBK BS_Dwn_Act received from %u", srcId); + return false; } } - - if (!found) { - LogMessage("Invalid CSBK BS_Dwn_Act received from %u", srcId); - return false; - } } if (bsId == 0xFFFFFFU) { diff --git a/DMRSlot.cpp b/DMRSlot.cpp index 04783a6..5bbfeac 100644 --- a/DMRSlot.cpp +++ b/DMRSlot.cpp @@ -25,6 +25,7 @@ #include #include +#include unsigned int CDMRSlot::m_id = 0U; unsigned int CDMRSlot::m_colorCode = 0U; @@ -1265,12 +1266,7 @@ bool CDMRSlot::validateId(unsigned int id) if (m_prefixes.size() == 0U) return true; - for (std::vector::const_iterator it = m_prefixes.begin(); it != m_prefixes.end(); ++it) { - if (prefix == *it) - return true; - } - - return false; + return std::find(m_prefixes.begin(), m_prefixes.end(), prefix) != m_prefixes.end(); } }