aboutsummaryrefslogtreecommitdiffstats
path: root/low-can-binding/can
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2019-12-04 16:19:28 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2020-01-09 16:25:36 +0100
commit7f905a75de0600ef0c2316db0f3deaa33aabd9e7 (patch)
tree08032124e1fae067c79594aa1138aa036e6c9e3f /low-can-binding/can
parent400c1a26178870a1cc94cbcab44efa949e76e955 (diff)
message: optimize getting subpart of a vector
Change-Id: Ifdaea3bf0969f15eb70629a92c0293ddeee33491 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'low-can-binding/can')
-rw-r--r--low-can-binding/can/message/message.cpp26
1 files 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<uint8_t> message_t::get_data_vector(int start, int end) const
{
- std::vector<uint8_t> ret;
- if(start >= 0)
- {
- if(end<length_)
- {
- for(int i=start;i<=end;i++)
- {
- ret.push_back(data_[i]);
- }
- }
- else
- {
- for(int i=start;i<length_;i++)
- {
- ret.push_back(data_[i]);
- }
- }
- }
- else
+ if ( start > length_ || end > length_ )
{
AFB_ERROR("Error index to get data vector, [%d-%d] - for length %d", start, end, length_);
+ return data_;
}
+
+ std::vector<uint8_t>::const_iterator first = data_.begin() + start;
+ std::vector<uint8_t>::const_iterator last = data_.begin() + end;
+ std::vector<uint8_t> ret(first, last);
+
return ret;
}