clang-tidy: convert loops to range based

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev
2025-06-16 15:37:27 -07:00
committed by Jari Sundell
parent bb8d677f6e
commit 0948b5f86a
26 changed files with 181 additions and 196 deletions
+6 -6
View File
@@ -55,14 +55,14 @@ TextElementList::print(char* first, char* last, Canvas::attributes_list* attribu
// Call print for each element even if first == last so that any
// attributes gets added to the list.
for (iterator itr = begin(); itr != end(); ++itr)
for (auto& itr : *this)
if (column-- > 0) {
char* columnEnd = std::min(last, first + *m_columnWidth);
if (columnEnd < first || columnEnd > last)
throw torrent::internal_error("TextElementList::print(...) columnEnd < first || columnEnd > last.");
first = (*itr)->print(first, columnEnd, attributes, target);
first = itr->print(first, columnEnd, attributes, target);
if (first > columnEnd)
throw torrent::internal_error("TextElementList::print(...) first > columnEnd.");
@@ -71,7 +71,7 @@ TextElementList::print(char* first, char* last, Canvas::attributes_list* attribu
first = columnEnd;
} else {
first = (*itr)->print(first, last, attributes, target);
first = itr->print(first, last, attributes, target);
}
return first;
@@ -82,15 +82,15 @@ TextElementList::max_length() {
extent_type length = 0;
int column = m_columnWidth != NULL ? m_column : 0;
for (iterator itr = begin(); itr != end(); ++itr) {
extent_type l = column-- > 0 ? std::min((*itr)->max_length(), *m_columnWidth) : (*itr)->max_length();
for (auto& itr : *this) {
extent_type l = column-- > 0 ? std::min(itr->max_length(), *m_columnWidth) : itr->max_length();
if (l == extent_full)
return extent_full;
length += l;
}
return length;
}
+6 -8
View File
@@ -295,15 +295,14 @@ print_status_throttle_limit(char* first, char* last, bool up, const ui::Throttle
char* firstc = throttle_str;
char* lastc = throttle_str + 40 - 1;
for (ui::ThrottleNameList::const_iterator itr = throttle_names.begin(), laste = throttle_names.end(); itr != laste; itr++) {
for (const auto& throttle_name : throttle_names) {
if (!(*itr).empty()) {
int64_t throttle_max = control->core()->retrieve_throttle_value(*itr, false, up);
if (!throttle_name.empty()) {
int64_t throttle_max = control->core()->retrieve_throttle_value(throttle_name, false, up);
if (throttle_max > 0)
firstc = print_buffer(firstc, lastc, "|%1.0f", (double)throttle_max / 1024.0);
}
}
// Add temp buffer (chop first char first) into main buffer if temp buffer isn't empty
@@ -321,10 +320,10 @@ print_status_throttle_rate(char* first, char* last, bool up, const ui::ThrottleN
char* firstc = throttle_str;
char* lastc = throttle_str + 50 - 1;
for (ui::ThrottleNameList::const_iterator itr = throttle_names.begin(), laste = throttle_names.end(); itr != laste; itr++) {
for (const auto& throttle_name : throttle_names) {
if (!(*itr).empty() && (up ? torrent::up_throttle_global()->is_throttled() : torrent::down_throttle_global()->is_throttled())) {
int64_t throttle_rate_value = control->core()->retrieve_throttle_value(*itr, true, up);
if (!throttle_name.empty() && (up ? torrent::up_throttle_global()->is_throttled() : torrent::down_throttle_global()->is_throttled())) {
int64_t throttle_rate_value = control->core()->retrieve_throttle_value(throttle_name, true, up);
if (throttle_rate_value > -1) {
double throttle_rate = (double)throttle_rate_value / 1024.0;
@@ -333,7 +332,6 @@ print_status_throttle_rate(char* first, char* last, bool up, const ui::ThrottleN
firstc = print_buffer(firstc, lastc, "|%3.1f", throttle_rate);
}
}
}
// Add temp buffer into main buffer if temp buffer isn't empty
+8 -8
View File
@@ -40,7 +40,7 @@ WindowDownloadTransferList::redraw() {
m_canvas->print(0, y, "%5u [P: %u F: %u]", (*itr)->index(), (*itr)->priority(), (*itr)->failed());
// Handle window size.
for (torrent::BlockList::const_iterator bItr = (*itr)->begin(), bLast = (*itr)->end(); bItr != bLast; ++bItr) {
for (const auto& bItr : **itr) {
if (m_canvas->get_x() >= m_canvas->width() - 1) {
if (++y >= m_canvas->height())
break;
@@ -51,22 +51,22 @@ WindowDownloadTransferList::redraw() {
char id;
chtype attr = A_NORMAL;
if (bItr->is_finished()) {
if (bItr.is_finished()) {
attr = A_REVERSE;
id = key_id(bItr->leader()->const_peer_info());
id = key_id(bItr.leader()->const_peer_info());
} else if (bItr->is_transfering()) {
} else if (bItr.is_transfering()) {
attr = A_BOLD;
id = key_id(bItr->leader()->const_peer_info());
id = key_id(bItr.leader()->const_peer_info());
} else if (bItr->queued()->size() >= 1) {
id = std::tolower(key_id(bItr->queued()->back()->const_peer_info()));
} else if (bItr.queued()->size() >= 1) {
id = std::tolower(key_id(bItr.queued()->back()->const_peer_info()));
} else {
id = '.';
}
if (bItr->size_all() > 1)
if (bItr.size_all() > 1)
attr |= A_UNDERLINE;
m_canvas->print_char(attr | id);