mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-05 17:52:29 +00:00
replace for_each with range loops
No advantage over the latter, which is simpler. Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
committed by
Jari Sundell
parent
8b663dd169
commit
84c0d516ef
@@ -286,9 +286,8 @@ DownloadFactory::receive_success() {
|
||||
if (torrent::log_groups[torrent::LOG_TORRENT_DEBUG].valid())
|
||||
log_created(download, rtorrent);
|
||||
|
||||
std::for_each(m_commands.begin(), m_commands.end(), [&download](const std::string& cmd) {
|
||||
rpc::parse_command_multiple_std(cmd, rpc::make_target(download));
|
||||
});
|
||||
for (const auto& command : m_commands)
|
||||
rpc::parse_command_multiple_std(command, rpc::make_target(download));
|
||||
|
||||
if (m_manager->download_list()->find(infohash) == m_manager->download_list()->end())
|
||||
throw torrent::input_error("The newly created download was removed.");
|
||||
|
||||
@@ -167,8 +167,10 @@ DownloadList::insert(Download* download) {
|
||||
|
||||
// This needs to be separated into two different calls to ensure
|
||||
// the download remains in the view.
|
||||
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [&download](View* v) { v->insert(download); });
|
||||
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [&download](View* v) { v->filter_download(download); });
|
||||
for (auto v : *control->view_manager())
|
||||
v->insert(download);
|
||||
for (auto v : *control->view_manager())
|
||||
v->filter_download(download);
|
||||
|
||||
DL_TRIGGER_EVENT(*itr, "event.download.inserted");
|
||||
|
||||
@@ -201,7 +203,8 @@ DownloadList::erase(iterator itr) {
|
||||
control->core()->download_store()->remove(*itr);
|
||||
|
||||
DL_TRIGGER_EVENT(*itr, "event.download.erased");
|
||||
std::for_each(control->view_manager()->begin(), control->view_manager()->end(), [itr](View* v) { v->erase(*itr); });
|
||||
for (auto v : *control->view_manager())
|
||||
v->erase(*itr);
|
||||
|
||||
torrent::download_remove(*(*itr)->download());
|
||||
delete *itr;
|
||||
|
||||
+4
-2
@@ -142,9 +142,11 @@ Manager::cleanup() {
|
||||
void
|
||||
Manager::shutdown(bool force) {
|
||||
if (!force)
|
||||
std::for_each(m_download_list->begin(), m_download_list->end(), [this](Download* d) { m_download_list->pause_default(d); });
|
||||
for (auto d : *m_download_list)
|
||||
m_download_list->pause_default(d);
|
||||
else
|
||||
std::for_each(m_download_list->begin(), m_download_list->end(), [this](Download* d) { m_download_list->close_quick(d); });
|
||||
for (auto d : *m_download_list)
|
||||
m_download_list->close_quick(d);
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -18,7 +18,8 @@ namespace core {
|
||||
|
||||
void
|
||||
ViewManager::clear() {
|
||||
std::for_each(begin(), end(), [](View* v) { delete v; });
|
||||
for (auto v : *this)
|
||||
delete v;
|
||||
|
||||
base_type::clear();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,8 @@ namespace display {
|
||||
|
||||
void
|
||||
TextElementList::clear() {
|
||||
std::for_each(begin(), end(), [](TextElement* t) { delete t; });
|
||||
for (auto t : *this)
|
||||
delete t;
|
||||
base_type::clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ WindowText::WindowText(rpc::target_type target, extent_type margin) :
|
||||
|
||||
void
|
||||
WindowText::clear() {
|
||||
std::for_each(begin(), end(), [](TextElement* text) { delete text; });
|
||||
for (auto t : *this)
|
||||
delete t;
|
||||
base_type::clear();
|
||||
|
||||
delete m_errorHandler;
|
||||
|
||||
+8
-12
@@ -68,17 +68,6 @@ PathInput::pressed(int key) {
|
||||
return true;
|
||||
}
|
||||
|
||||
struct _transform_filename {
|
||||
void operator () (utils::directory_entry& entry) {
|
||||
#ifdef __sun__
|
||||
if (entry.s_type & S_IFDIR)
|
||||
#else
|
||||
if (entry.s_type == DT_DIR)
|
||||
#endif
|
||||
entry.s_name += '/';
|
||||
}
|
||||
};
|
||||
|
||||
void
|
||||
PathInput::receive_do_complete() {
|
||||
lt_log_print(torrent::LOG_UI_EVENTS, "path_input: received completion");
|
||||
@@ -93,7 +82,14 @@ PathInput::receive_do_complete() {
|
||||
return;
|
||||
}
|
||||
|
||||
std::for_each(dir.begin(), dir.end(), _transform_filename());
|
||||
for (auto& entry : dir) {
|
||||
#ifdef __sun__
|
||||
if (entry.s_type & S_IFDIR)
|
||||
#else
|
||||
if (entry.s_type == DT_DIR)
|
||||
#endif
|
||||
entry.s_name += '/';
|
||||
}
|
||||
|
||||
range_type r = find_incomplete(dir, str().substr(dirEnd, get_pos()));
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
namespace rpc {
|
||||
|
||||
CommandScheduler::~CommandScheduler() {
|
||||
std::for_each(begin(), end(), [](CommandSchedulerItem* item) { delete item; });
|
||||
for (auto item : *this)
|
||||
delete item;
|
||||
}
|
||||
|
||||
CommandScheduler::iterator
|
||||
|
||||
@@ -63,7 +63,8 @@ ElementPeerList::ElementPeerList(core::Download* d) :
|
||||
|
||||
torrent::ConnectionList* connection_list = m_download->download()->connection_list();
|
||||
|
||||
std::for_each(connection_list->begin(), connection_list->end(), [&](torrent::Peer* peer) { m_list.push_back(peer); });
|
||||
for (auto peer : *connection_list)
|
||||
m_list.push_back(peer);
|
||||
|
||||
m_peer_connected = connection_list->signal_connected().insert(connection_list->signal_connected().end(),
|
||||
std::bind(&ElementPeerList::receive_peer_connected, this, std::placeholders::_1));
|
||||
|
||||
+13
-18
@@ -6,21 +6,6 @@
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <torrent/utils/log.h>
|
||||
|
||||
static void
|
||||
dump_failure_log(const failure_type& failure) {
|
||||
if (failure.log->empty())
|
||||
return;
|
||||
|
||||
std::cout << std::endl << failure.name << std::endl;
|
||||
|
||||
// Doesn't print dump messages as log_buffer drops them.
|
||||
std::for_each(failure.log->begin(), failure.log->end(), [](const torrent::log_entry& entry) {
|
||||
std::cout << entry.timestamp << ' ' << entry.message << '\n';
|
||||
});
|
||||
|
||||
std::cout << std::flush;
|
||||
}
|
||||
|
||||
static void
|
||||
dump_failures(const failure_list_type& failures) {
|
||||
if (failures.empty())
|
||||
@@ -31,9 +16,19 @@ dump_failures(const failure_list_type& failures) {
|
||||
<< "Failed Test Logs:" << std::endl
|
||||
<< "=================" << std::endl;
|
||||
|
||||
std::for_each(failures.begin(), failures.end(), [](const failure_type& failure) {
|
||||
dump_failure_log(failure);
|
||||
});
|
||||
for (const auto& failure : failures) {
|
||||
if (failure.log->empty())
|
||||
return;
|
||||
|
||||
std::cout << '\n'
|
||||
<< failure.name << '\n';
|
||||
|
||||
// Doesn't print dump messages as log_buffer drops them.
|
||||
for (const auto& entry : *failure.log)
|
||||
std::cout << entry.timestamp << ' ' << entry.message << '\n';
|
||||
|
||||
std::cout << std::flush;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user