From 006690c628ebd6f8ddc2021513828099fdb7ca94 Mon Sep 17 00:00:00 2001 From: Tommaso Pecorella Date: Sat, 1 Oct 2022 19:24:38 +0200 Subject: [PATCH] lte: fix redundant vector copy --- src/lte/model/lte-spectrum-phy.cc | 22 ++++++---------------- src/lte/model/lte-ue-phy.cc | 22 ++++++---------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/src/lte/model/lte-spectrum-phy.cc b/src/lte/model/lte-spectrum-phy.cc index 9b541600d..a88eaaa2e 100644 --- a/src/lte/model/lte-spectrum-phy.cc +++ b/src/lte/model/lte-spectrum-phy.cc @@ -1295,25 +1295,15 @@ void LteSpectrumPhy::SetTxModeGain (uint8_t txMode, double gain) { NS_LOG_FUNCTION (this << " txmode " << (uint16_t)txMode << " gain " << gain); - // convert to linear - gain = std::pow (10.0, (gain / 10.0)); - if (m_txModeGain.size () < txMode) + if (txMode > 0) { - m_txModeGain.resize (txMode); - } - std::vector temp; - temp = m_txModeGain; - m_txModeGain.clear (); - for (uint8_t i = 0; i < temp.size (); i++) - { - if (i == txMode - 1) + // convert to linear + double gainLin = std::pow (10.0, (gain / 10.0)); + if (m_txModeGain.size () < txMode) { - m_txModeGain.push_back (gain); - } - else - { - m_txModeGain.push_back (temp.at (i)); + m_txModeGain.resize (txMode); } + m_txModeGain.at (txMode - 1) = gainLin; } } diff --git a/src/lte/model/lte-ue-phy.cc b/src/lte/model/lte-ue-phy.cc index 99d38dcfd..4a9a85ecd 100644 --- a/src/lte/model/lte-ue-phy.cc +++ b/src/lte/model/lte-ue-phy.cc @@ -1728,25 +1728,15 @@ void LteUePhy::SetTxModeGain (uint8_t txMode, double gain) { NS_LOG_FUNCTION (this << gain); - // convert to linear - double gainLin = std::pow (10.0, (gain / 10.0)); - if (m_txModeGain.size () < txMode) + if (txMode > 0) { - m_txModeGain.resize (txMode); - } - std::vector temp; - temp = m_txModeGain; - m_txModeGain.clear (); - for (uint8_t i = 0; i < temp.size (); i++) - { - if (i == txMode - 1) + // convert to linear + double gainLin = std::pow (10.0, (gain / 10.0)); + if (m_txModeGain.size () < txMode) { - m_txModeGain.push_back (gainLin); - } - else - { - m_txModeGain.push_back (temp.at (i)); + m_txModeGain.resize (txMode); } + m_txModeGain.at (txMode - 1) = gainLin; } // forward the info to DL LteSpectrumPhy m_downlinkSpectrumPhy->SetTxModeGain (txMode, gain);