From c050c224f3de634f15dc673d3920a8b5ecaf902e 2017-09-05 16:17:38 From: Alexandre Leroux Date: 2017-09-05 16:17:38 Subject: [PATCH] Uses std::vector instead of QVector in ArrayData (1) std::vector will be better for inserting data during merge operation --- diff --git a/core/include/Common/SortUtils.h b/core/include/Common/SortUtils.h index 0536439..f0fda7b 100644 --- a/core/include/Common/SortUtils.h +++ b/core/include/Common/SortUtils.h @@ -77,7 +77,7 @@ struct SortUtils { for (auto i = 0, componentIndex = 0, permutationIndex = 0; i < containerSize; ++i, componentIndex = i % nbValues, permutationIndex = i / nbValues) { auto insertIndex = sortPermutation.at(permutationIndex) * nbValues + componentIndex; - sortedData.append(container.at(insertIndex)); + sortedData.push_back(container.at(insertIndex)); } return sortedData; diff --git a/core/include/Data/ArrayData.h b/core/include/Data/ArrayData.h index e14f532..d676c70 100644 --- a/core/include/Data/ArrayData.h +++ b/core/include/Data/ArrayData.h @@ -13,7 +13,7 @@ template class ArrayData; -using DataContainer = QVector; +using DataContainer = std::vector; namespace arraydata_detail { @@ -363,9 +363,8 @@ public: * @remarks this method is only available for a unidimensional ArrayData */ template > - const QVector &cdata() const noexcept + DataContainer cdata() const noexcept { - QReadLocker locker{&m_Lock}; return m_Data; } diff --git a/core/include/Data/DataSeries.h b/core/include/Data/DataSeries.h index a5a9d68..9fa5b0f 100644 --- a/core/include/Data/DataSeries.h +++ b/core/include/Data/DataSeries.h @@ -155,8 +155,8 @@ public: SqpRange range() const override { - if (!m_XAxisData->cdata().isEmpty()) { - return SqpRange{m_XAxisData->cdata().first(), m_XAxisData->cdata().last()}; + if (!m_XAxisData->cdata().empty()) { + return SqpRange{m_XAxisData->cdata().front(), m_XAxisData->cdata().back()}; } return SqpRange{}; diff --git a/core/include/Data/ScalarSeries.h b/core/include/Data/ScalarSeries.h index 1a745e5..82e4ec7 100644 --- a/core/include/Data/ScalarSeries.h +++ b/core/include/Data/ScalarSeries.h @@ -16,7 +16,7 @@ public: * @param xAxisData x-axis data * @param valuesData values data */ - explicit ScalarSeries(QVector xAxisData, QVector valuesData, + explicit ScalarSeries(std::vector xAxisData, std::vector valuesData, const Unit &xAxisUnit, const Unit &valuesUnit); std::unique_ptr clone() const override; diff --git a/core/include/Data/VectorSeries.h b/core/include/Data/VectorSeries.h index 99d49cd..c00ed8b 100644 --- a/core/include/Data/VectorSeries.h +++ b/core/include/Data/VectorSeries.h @@ -18,12 +18,12 @@ public: * @param yvaluesData y-values data * @param zvaluesData z-values data */ - explicit VectorSeries(QVector xAxisData, QVector xValuesData, - QVector yValuesData, QVector zValuesData, + explicit VectorSeries(std::vector xAxisData, std::vector xValuesData, + std::vector yValuesData, std::vector zValuesData, const Unit &xAxisUnit, const Unit &valuesUnit); /// Default Ctor - explicit VectorSeries(QVector xAxisData, QVector valuesData, + explicit VectorSeries(std::vector xAxisData, std::vector valuesData, const Unit &xAxisUnit, const Unit &valuesUnit); std::unique_ptr clone() const; diff --git a/core/src/Data/ScalarSeries.cpp b/core/src/Data/ScalarSeries.cpp index 49bec2e..4dd44f5 100644 --- a/core/src/Data/ScalarSeries.cpp +++ b/core/src/Data/ScalarSeries.cpp @@ -1,6 +1,6 @@ #include -ScalarSeries::ScalarSeries(QVector xAxisData, QVector valuesData, +ScalarSeries::ScalarSeries(std::vector xAxisData, std::vector valuesData, const Unit &xAxisUnit, const Unit &valuesUnit) : DataSeries{std::make_shared >(std::move(xAxisData)), xAxisUnit, std::make_shared >(std::move(valuesData)), valuesUnit} @@ -14,18 +14,18 @@ std::unique_ptr ScalarSeries::clone() const std::shared_ptr ScalarSeries::subDataSeries(const SqpRange &range) { - auto subXAxisData = QVector(); - auto subValuesData = QVector(); + auto subXAxisData = std::vector(); + auto subValuesData = std::vector(); this->lockRead(); { auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); for (auto it = bounds.first; it != bounds.second; ++it) { - subXAxisData.append(it->x()); - subValuesData.append(it->value()); + subXAxisData.push_back(it->x()); + subValuesData.push_back(it->value()); } } this->unlock(); - return std::make_shared(subXAxisData, subValuesData, this->xAxisUnit(), - this->valuesUnit()); + return std::make_shared(std::move(subXAxisData), std::move(subValuesData), + this->xAxisUnit(), this->valuesUnit()); } diff --git a/core/src/Data/VectorSeries.cpp b/core/src/Data/VectorSeries.cpp index b7c9bf7..879d689 100644 --- a/core/src/Data/VectorSeries.cpp +++ b/core/src/Data/VectorSeries.cpp @@ -19,18 +19,22 @@ namespace { * @remarks the three components are consumed * @sa ArrayData */ -QVector flatten(QVector xValues, QVector yValues, QVector zValues) +std::vector flatten(std::vector xValues, std::vector yValues, + std::vector zValues) { if (xValues.size() != yValues.size() || xValues.size() != zValues.size()) { /// @todo ALX : log return {}; } - auto result = QVector{}; + auto result = std::vector(); result.reserve(xValues.size() * 3); - while (!xValues.isEmpty()) { - result.append({xValues.takeFirst(), yValues.takeFirst(), zValues.takeFirst()}); + while (!xValues.empty()) { + result.insert(result.cend(), {xValues.front(), yValues.front(), zValues.front()}); + xValues.erase(xValues.begin()); + yValues.erase(yValues.begin()); + zValues.erase(zValues.begin()); } return result; @@ -38,8 +42,8 @@ QVector flatten(QVector xValues, QVector yValues, QVecto } // namespace -VectorSeries::VectorSeries(QVector xAxisData, QVector xValuesData, - QVector yValuesData, QVector zValuesData, +VectorSeries::VectorSeries(std::vector xAxisData, std::vector xValuesData, + std::vector yValuesData, std::vector zValuesData, const Unit &xAxisUnit, const Unit &valuesUnit) : VectorSeries{std::move(xAxisData), flatten(std::move(xValuesData), std::move(yValuesData), std::move(zValuesData)), @@ -47,7 +51,7 @@ VectorSeries::VectorSeries(QVector xAxisData, QVector xValuesDat { } -VectorSeries::VectorSeries(QVector xAxisData, QVector valuesData, +VectorSeries::VectorSeries(std::vector xAxisData, std::vector valuesData, const Unit &xAxisUnit, const Unit &valuesUnit) : DataSeries{std::make_shared >(std::move(xAxisData)), xAxisUnit, std::make_shared >(std::move(valuesData), 3), valuesUnit} @@ -61,23 +65,24 @@ std::unique_ptr VectorSeries::clone() const std::shared_ptr VectorSeries::subDataSeries(const SqpRange &range) { - auto subXAxisData = QVector(); - auto subXValuesData = QVector(); - auto subYValuesData = QVector(); - auto subZValuesData = QVector(); + auto subXAxisData = std::vector(); + auto subXValuesData = std::vector(); + auto subYValuesData = std::vector(); + auto subZValuesData = std::vector(); this->lockRead(); { auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); for (auto it = bounds.first; it != bounds.second; ++it) { - subXAxisData.append(it->x()); - subXValuesData.append(it->value(0)); - subYValuesData.append(it->value(1)); - subZValuesData.append(it->value(2)); + subXAxisData.push_back(it->x()); + subXValuesData.push_back(it->value(0)); + subYValuesData.push_back(it->value(1)); + subZValuesData.push_back(it->value(2)); } } this->unlock(); - return std::make_shared(subXAxisData, subXValuesData, subYValuesData, - subZValuesData, this->xAxisUnit(), this->valuesUnit()); + return std::make_shared(std::move(subXAxisData), std::move(subXValuesData), + std::move(subYValuesData), std::move(subZValuesData), + this->xAxisUnit(), this->valuesUnit()); } diff --git a/plugins/amda/src/AmdaResultParser.cpp b/plugins/amda/src/AmdaResultParser.cpp index 73af4a0..e7db277 100644 --- a/plugins/amda/src/AmdaResultParser.cpp +++ b/plugins/amda/src/AmdaResultParser.cpp @@ -194,15 +194,16 @@ std::shared_ptr AmdaResultParser::readTxt(const QString &filePath, case ValueType::SCALAR: Q_ASSERT(results.second.size() == 1); return std::make_shared( - std::move(results.first), std::move(results.second.takeFirst()), xAxisUnit, Unit{}); + std::move(results.first.toStdVector()), + std::move(results.second.takeFirst().toStdVector()), xAxisUnit, Unit{}); case ValueType::VECTOR: { Q_ASSERT(results.second.size() == 3); - auto xValues = results.second.takeFirst(); - auto yValues = results.second.takeFirst(); - auto zValues = results.second.takeFirst(); - return std::make_shared(std::move(results.first), std::move(xValues), - std::move(yValues), std::move(zValues), xAxisUnit, - Unit{}); + auto xValues = results.second.takeFirst().toStdVector(); + auto yValues = results.second.takeFirst().toStdVector(); + auto zValues = results.second.takeFirst().toStdVector(); + return std::make_shared(std::move(results.first.toStdVector()), + std::move(xValues), std::move(yValues), + std::move(zValues), xAxisUnit, Unit{}); } case ValueType::UNKNOWN: // Invalid case diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index 4781d41..661a78f 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -18,7 +18,7 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, auto dataIndex = 0; // Gets the timerange from the parameters - double freq = 1.0; + double freq = 100.0; double start = std::ceil(dataRangeRequested.m_TStart * freq); // 100 htz double end = std::floor(dataRangeRequested.m_TEnd * freq); // 100 htz @@ -30,10 +30,10 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, // Generates scalar series containing cosinus values (one value per second) auto dataCount = end - start; - auto xAxisData = QVector{}; + auto xAxisData = std::vector{}; xAxisData.resize(dataCount); - auto valuesData = QVector{}; + auto valuesData = std::vector{}; valuesData.resize(dataCount); int progress = 0; @@ -43,8 +43,8 @@ std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, if (it != m_VariableToEnableProvider.end() && it.value()) { const auto timeOnFreq = time / freq; - xAxisData.replace(dataIndex, timeOnFreq); - valuesData.replace(dataIndex, std::cos(timeOnFreq)); + xAxisData[dataIndex] = timeOnFreq; + valuesData[dataIndex] = std::cos(timeOnFreq); // progression int currentProgress = (time - start) * 100.0 / progressEnd;