internet, lte, spectrum, wifi: Pre-allocate memory when initializing vectors

This commit is contained in:
Eduardo Almeida
2023-09-13 18:53:53 +01:00
parent a4b43cb532
commit ec2c79b5e0
10 changed files with 29 additions and 80 deletions

View File

@@ -220,11 +220,7 @@ Ipv6InterfaceContainer
Ipv6AddressHelper::Assign(const NetDeviceContainer& c)
{
NS_LOG_FUNCTION(this);
std::vector<bool> withConfiguration;
for (uint32_t i = 0; i < c.GetN(); ++i)
{
withConfiguration.push_back(true);
}
std::vector<bool> withConfiguration(c.GetN(), true);
return Assign(c, withConfiguration);
}
@@ -232,11 +228,7 @@ Ipv6InterfaceContainer
Ipv6AddressHelper::Assign(const NetDeviceContainer& c, std::vector<bool> withConfiguration)
{
NS_LOG_FUNCTION(this);
std::vector<bool> onLink;
for (uint32_t i = 0; i < c.GetN(); ++i)
{
onLink.push_back(true);
}
std::vector<bool> onLink(c.GetN(), true);
return Assign(c, withConfiguration, onLink);
}
@@ -312,11 +304,7 @@ Ipv6InterfaceContainer
Ipv6AddressHelper::AssignWithoutAddress(const NetDeviceContainer& c)
{
NS_LOG_FUNCTION(this);
std::vector<bool> withConfiguration;
for (uint32_t i = 0; i < c.GetN(); ++i)
{
withConfiguration.push_back(false);
}
std::vector<bool> withConfiguration(c.GetN(), false);
return Assign(c, withConfiguration);
}
@@ -324,13 +312,10 @@ Ipv6InterfaceContainer
Ipv6AddressHelper::AssignWithoutOnLink(const NetDeviceContainer& c)
{
NS_LOG_FUNCTION(this);
std::vector<bool> withConfiguration;
std::vector<bool> onLink;
for (uint32_t i = 0; i < c.GetN(); ++i)
{
withConfiguration.push_back(true);
onLink.push_back(false);
}
std::vector<bool> withConfiguration(c.GetN(), true);
std::vector<bool> onLink(c.GetN(), false);
return Assign(c, withConfiguration, onLink);
}

View File

@@ -1282,10 +1282,7 @@ CqaFfMacScheduler::DoSchedDlTriggerReq(
std::vector<uint8_t> sbCqis;
if (itCqi == m_a30CqiRxed.end())
{
for (uint8_t k = 0; k < nLayer; k++)
{
sbCqis.push_back(1); // start with lowest value
}
sbCqis = std::vector<uint8_t>(nLayer, 1); // start with lowest value
}
else
{

View File

@@ -917,10 +917,7 @@ FdMtFfMacScheduler::DoSchedDlTriggerReq(
std::vector<uint8_t> sbCqi;
if (itCqi == m_a30CqiRxed.end())
{
for (uint8_t k = 0; k < nLayer; k++)
{
sbCqi.push_back(1); // start with lowest value
}
sbCqi = std::vector<uint8_t>(nLayer, 1); // start with lowest value
}
else
{

View File

@@ -1207,10 +1207,7 @@ FdTbfqFfMacScheduler::DoSchedDlTriggerReq(
std::vector<uint8_t> sbCqi;
if (itCqi == m_a30CqiRxed.end())
{
for (uint8_t k = 0; k < nLayer; k++)
{
sbCqi.push_back(1); // start with lowest value
}
sbCqi = std::vector<uint8_t>(nLayer, 1); // start with lowest value
}
else
{

View File

@@ -984,10 +984,7 @@ PfFfMacScheduler::DoSchedDlTriggerReq(
std::vector<uint8_t> sbCqi;
if (itCqi == m_a30CqiRxed.end())
{
for (uint8_t k = 0; k < nLayer; k++)
{
sbCqi.push_back(1); // start with lowest value
}
sbCqi = std::vector<uint8_t>(nLayer, 1); // start with lowest value
}
else
{

View File

@@ -1150,10 +1150,7 @@ PssFfMacScheduler::DoSchedDlTriggerReq(
std::vector<uint8_t> sbCqis;
if (itCqi == m_a30CqiRxed.end())
{
for (uint8_t k = 0; k < nLayer; k++)
{
sbCqis.push_back(1); // start with lowest value
}
sbCqis = std::vector<uint8_t>(nLayer, 1); // start with lowest value
}
else
{
@@ -1230,10 +1227,7 @@ PssFfMacScheduler::DoSchedDlTriggerReq(
std::vector<uint8_t> sbCqis;
if (itCqi == m_a30CqiRxed.end())
{
for (uint8_t k = 0; k < nLayer; k++)
{
sbCqis.push_back(1); // start with lowest value
}
sbCqis = std::vector<uint8_t>(nLayer, 1); // start with lowest value
}
else
{
@@ -1336,10 +1330,7 @@ PssFfMacScheduler::DoSchedDlTriggerReq(
std::vector<uint8_t> sbCqis;
if (itCqi == m_a30CqiRxed.end())
{
for (uint8_t k = 0; k < nLayer; k++)
{
sbCqis.push_back(1); // start with lowest value
}
sbCqis = std::vector<uint8_t>(nLayer, 1); // start with lowest value
}
else
{

View File

@@ -921,10 +921,7 @@ TtaFfMacScheduler::DoSchedDlTriggerReq(
std::vector<uint8_t> sbCqi;
if (itSbCqi == m_a30CqiRxed.end())
{
for (uint8_t k = 0; k < nLayer; k++)
{
sbCqi.push_back(1); // start with lowest value
}
sbCqi = std::vector<uint8_t>(nLayer, 1); // start with lowest value
}
else
{

View File

@@ -2197,12 +2197,11 @@ ThreeGppChannelModel::CalcAttenuationOfBlockage(
{
NS_LOG_FUNCTION(this);
DoubleVector powerAttenuation;
uint8_t clusterNum = clusterAOA.size();
for (uint8_t cInd = 0; cInd < clusterNum; cInd++)
{
powerAttenuation.push_back(0); // Initial power attenuation for all clusters to be 0 dB;
}
auto clusterNum = clusterAOA.size();
// Initial power attenuation for all clusters to be 0 dB
DoubleVector powerAttenuation(clusterNum, 0);
// step a: the number of non-self blocking blockers is stored in m_numNonSelfBlocking.
// step b:Generate the size and location of each blocker

View File

@@ -2229,33 +2229,24 @@ MinstrelHtWifiManager::GetLowestIndex(MinstrelHtWifiRemoteStation* station, uint
WifiModeList
MinstrelHtWifiManager::GetHeDeviceMcsList() const
{
WifiModeList heMcsList;
for (const auto& mode : GetPhy()->GetMcsList(WIFI_MOD_CLASS_HE))
{
heMcsList.push_back(mode);
}
const auto& mcsList = GetPhy()->GetMcsList(WIFI_MOD_CLASS_HE);
WifiModeList heMcsList(mcsList.begin(), mcsList.end());
return heMcsList;
}
WifiModeList
MinstrelHtWifiManager::GetVhtDeviceMcsList() const
{
WifiModeList vhtMcsList;
for (const auto& mode : GetPhy()->GetMcsList(WIFI_MOD_CLASS_VHT))
{
vhtMcsList.push_back(mode);
}
const auto& mcsList = GetPhy()->GetMcsList(WIFI_MOD_CLASS_VHT);
WifiModeList vhtMcsList(mcsList.begin(), mcsList.end());
return vhtMcsList;
}
WifiModeList
MinstrelHtWifiManager::GetHtDeviceMcsList() const
{
WifiModeList htMcsList;
for (const auto& mode : GetPhy()->GetMcsList(WIFI_MOD_CLASS_HT))
{
htMcsList.push_back(mode);
}
const auto& mcsList = GetPhy()->GetMcsList(WIFI_MOD_CLASS_HT);
WifiModeList htMcsList(mcsList.begin(), mcsList.end());
return htMcsList;
}

View File

@@ -390,11 +390,9 @@ WifiRemoteStationManager::AddAllSupportedMcs(Mac48Address address)
NS_LOG_FUNCTION(this << address);
NS_ASSERT(!address.IsGroup());
auto state = LookupState(address);
state->m_operationalMcsSet.clear();
for (const auto& mcs : m_wifiPhy->GetMcsList())
{
state->m_operationalMcsSet.push_back(mcs);
}
const auto& mcsList = m_wifiPhy->GetMcsList();
state->m_operationalMcsSet = WifiModeList(mcsList.begin(), mcsList.end());
}
void