Move to StackVec for timestamp packet container.

Do not use std::vector in hot path.

Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:
Michal Mrozek
2022-03-02 18:51:53 +00:00
committed by Compute-Runtime-Automation
parent 30ea8ea48e
commit 721c59d3d5
4 changed files with 107 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018-2021 Intel Corporation
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -158,6 +158,32 @@ class StackVec {
return *this;
}
template <typename RhsT>
void swap(RhsT &rhs) {
if (this->usesDynamicMem() && rhs.usesDynamicMem()) {
this->dynamicMem->swap(*rhs.dynamicMem);
return;
}
size_t smallerSize = this->size() < rhs.size() ? this->size() : rhs.size();
size_t i = 0;
for (; i < smallerSize; ++i) {
std::swap((*this)[i], rhs[i]);
}
if (this->size() == smallerSize) {
auto biggerSize = rhs.size();
for (; i < biggerSize; ++i) {
this->push_back(std::move(rhs[i]));
}
rhs.resize(smallerSize);
} else {
auto biggerSize = this->size();
for (; i < biggerSize; ++i) {
rhs.push_back(std::move((*this)[i]));
}
this->resize(smallerSize);
}
}
~StackVec() {
if (usesDynamicMem()) {
delete dynamicMem;
@@ -232,6 +258,10 @@ class StackVec {
return *(reinterpret_cast<DataType *>(onStackMemRawBytes) + idx);
}
DataType &at(std::size_t idx) { return this->operator[](idx); }
const DataType &at(std::size_t idx) const { return this->operator[](idx); }
const DataType &operator[](std::size_t idx) const {
if (usesDynamicMem()) {
return (*dynamicMem)[idx];
@@ -307,6 +337,8 @@ class StackVec {
}
private:
template <typename RhsDataType, size_t RhsOnStackCapacity, typename RhsStackSizeT>
friend class StackVec;
void setUsesDynamicMem() {
this->onStackSize = std::numeric_limits<decltype(onStackSize)>::max();
}