lib: Use const-ref in for loops instead of const-copy

This is potentially a performance issue, even though it doesn't have
a big impact in this context. Clang will warn about it, and this fixes
the compiler warning.
This commit is contained in:
Martin Braun 2021-01-08 13:23:17 +01:00 committed by Aaron Rossetto
parent 49e5ef8153
commit 47623aabb4
7 changed files with 9 additions and 9 deletions

View File

@ -59,7 +59,7 @@ bool uhd::image_loader::load(
} else
return get_image_loaders().at(type)(image_loader_args);
} else {
for (const loader_fcn_pair_t& loader_fcn_pair : get_image_loaders()) {
for (const auto& loader_fcn_pair : get_image_loaders()) {
if (loader_fcn_pair.second(image_loader_args))
return true;
}

View File

@ -750,7 +750,7 @@ b200_impl::b200_impl(
////////////////////////////////////////////////////////////////////
_radio_perifs[0].fp_gpio =
gpio_atr_3000::make(_radio_perifs[0].ctrl, TOREG(SR_FP_GPIO), RB32_FP_GPIO);
for (const gpio_attr_map_t::value_type attr : gpio_attr_map) {
for (const auto& attr : gpio_attr_map) {
switch (attr.first) {
case usrp::gpio_atr::GPIO_SRC:
_tree

View File

@ -54,7 +54,7 @@ public:
_atr_fdx_reg.initialize(*_iface, true);
_ddr_reg.initialize(*_iface, true);
_atr_disable_reg.initialize(*_iface, true);
for (const gpio_attr_map_t::value_type attr : gpio_attr_map) {
for (const auto& attr : gpio_attr_map) {
if (attr.first == usrp::gpio_atr::GPIO_SRC
|| attr.first == usrp::gpio_atr::GPIO_READBACK) {
// Don't set the SRC and READBACK, they're handled elsewhere.

View File

@ -158,7 +158,7 @@ static const boost::array<double, 17> tvrx_gains_volts = {{0.8,
static uhd::dict<std::string, gain_range_t> get_tvrx_gain_ranges(void)
{
double rfmax = 0.0, rfmin = FLT_MAX;
for (const std::string range : tvrx_rf_gains_db.keys()) {
for (const std::string& range : tvrx_rf_gains_db.keys()) {
double my_max = tvrx_rf_gains_db[range].back(); // we're assuming it's monotonic
double my_min =
tvrx_rf_gains_db[range].front(); // if it's not this is wrong wrong wrong

View File

@ -227,7 +227,7 @@ void magnesium_radio_control_impl::_init_frontend_subtree(
// TX gains
std::vector<std::string> tx_gain_names = get_tx_gain_names(chan_idx);
tx_gain_names.push_back("all");
for (const auto gain_name : tx_gain_names) {
for (const auto& gain_name : tx_gain_names) {
subtree->create<double>(tx_fe_path / "gains" / gain_name / "value")
.set_coercer([this, chan_idx, gain_name](const double gain) {
return this->set_tx_gain(gain, gain_name, chan_idx);
@ -256,7 +256,7 @@ void magnesium_radio_control_impl::_init_frontend_subtree(
// RX gains
std::vector<std::string> rx_gain_names = get_rx_gain_names(chan_idx);
rx_gain_names.push_back("all");
for (const auto gain_name : rx_gain_names) {
for (const auto& gain_name : rx_gain_names) {
subtree->create<double>(rx_fe_path / "gains" / gain_name / "value")
.set_coercer([this, chan_idx, gain_name](const double gain) {
return this->set_rx_gain(gain, gain_name, chan_idx);

View File

@ -159,7 +159,7 @@ public:
// TODO: Do we need this section? Since the _fp_gpio handles state now, we
// don't need to stash values here. We only need this if we want to set
// anything to a default value.
for (const gpio_atr::gpio_attr_map_t::value_type attr : gpio_atr::gpio_attr_map) {
for (const auto& attr : gpio_atr::gpio_attr_map) {
// TODO: Default values?
if (attr.first == usrp::gpio_atr::GPIO_SRC) {
// Don't set the SRC

View File

@ -193,8 +193,8 @@ static std::string get_rfnoc_blocks_pp_string(rfnoc::rfnoc_graph::sptr graph)
{
std::stringstream ss;
ss << "RFNoC blocks on this device:" << std::endl << std::endl;
for (const std::string& name : graph->find_blocks("")) {
ss << "* " << name << std::endl;
for (const auto& name : graph->find_blocks("")) {
ss << "* " << name.to_string() << std::endl;
}
return ss.str();
}