From 7f905a75de0600ef0c2316db0f3deaa33aabd9e7 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Wed, 4 Dec 2019 16:19:28 +0100 Subject: message: optimize getting subpart of a vector Change-Id: Ifdaea3bf0969f15eb70629a92c0293ddeee33491 Signed-off-by: Romain Forlot --- low-can-binding/can/message/message.cpp | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/low-can-binding/can/message/message.cpp b/low-can-binding/can/message/message.cpp index 191e1f23..22887c9a 100644 --- a/low-can-binding/can/message/message.cpp +++ b/low-can-binding/can/message/message.cpp @@ -85,28 +85,16 @@ const uint8_t* message_t::get_data() const /// const std::vector message_t::get_data_vector(int start, int end) const { - std::vector ret; - if(start >= 0) - { - if(end length_ || end > length_ ) { AFB_ERROR("Error index to get data vector, [%d-%d] - for length %d", start, end, length_); + return data_; } + + std::vector::const_iterator first = data_.begin() + start; + std::vector::const_iterator last = data_.begin() + end; + std::vector ret(first, last); + return ret; } -- cgit 1.2.3-korg