diff --git a/libtorrent/src/dht/dht_hash_map.h b/libtorrent/src/dht/dht_hash_map.h index ff4e3030..5bf0d7df 100644 --- a/libtorrent/src/dht/dht_hash_map.h +++ b/libtorrent/src/dht/dht_hash_map.h @@ -96,7 +96,7 @@ class DhtTrackerList : public std::unordered_map { inline DhtNode* DhtNodeList::add_node(DhtNode* n) { - insert(std::make_pair((const HashString*)n, (DhtNode*)n)); + emplace((const HashString*)n, (DhtNode*)n); return n; } diff --git a/libtorrent/src/dht/dht_router.cc b/libtorrent/src/dht/dht_router.cc index fe7b7a63..7d040b9d 100644 --- a/libtorrent/src/dht/dht_router.cc +++ b/libtorrent/src/dht/dht_router.cc @@ -96,7 +96,7 @@ DhtRouter::DhtRouter(const Object& cache, const rak::socket_address* sa) : LT_LOG_THIS("creating (address:%s)", sa->pretty_address_str().c_str()); set_bucket(new DhtBucket(zero_id, ones_id)); - m_routingTable.insert(std::make_pair(bucket()->id_range_end(), bucket())); + m_routingTable.emplace(bucket()->id_range_end(), bucket()); if (cache.has_key("nodes")) { const Object::map_type& nodes = cache.get_key_map("nodes"); @@ -121,7 +121,7 @@ DhtRouter::DhtRouter(const Object& cache, const rak::socket_address* sa) : Object::list_type::const_iterator litr = itr->as_list().begin(); const std::string& host = litr->as_string(); int port = (++litr)->as_value(); - m_contacts->push_back(std::make_pair(host, port)); + m_contacts->emplace_back(host, port); } } } @@ -181,7 +181,7 @@ DhtRouter::get_tracker(const HashString& hash, bool create) { if (!create) return NULL; - std::pair res = m_trackers.insert(std::make_pair(hash, new DhtTracker())); + std::pair res = m_trackers.emplace(hash, new DhtTracker()); if (!res.second) throw internal_error("DhtRouter::get_tracker did not actually insert tracker."); @@ -239,7 +239,7 @@ DhtRouter::add_contact(const std::string& host, int port) { if (m_contacts->size() >= num_bootstrap_contacts) m_contacts->pop_front(); - m_contacts->push_back(std::make_pair(host, port)); + m_contacts->emplace_back(host, port); } } @@ -364,8 +364,8 @@ DhtRouter::store_cache(Object* container) const { for (std::deque::const_iterator itr = m_contacts->begin(); itr != m_contacts->end(); ++itr) { Object::list_type& list = contacts.insert_back(Object::create_list()).as_list(); - list.push_back(itr->first); - list.push_back(itr->second); + list.emplace_back(itr->first); + list.emplace_back(itr->second); } } @@ -547,7 +547,7 @@ DhtRouter::split_bucket(const DhtBucketList::iterator& itr, DhtNode* node) { throw internal_error("DhtRouter::split_bucket router ID ended up in wrong bucket."); // Insert new bucket with iterator hint = just before current bucket. - DhtBucketList::iterator other = m_routingTable.insert(itr, std::make_pair(newBucket->id_range_end(), newBucket)); + DhtBucketList::iterator other = m_routingTable.emplace_hint(itr, newBucket->id_range_end(), newBucket); // Check that the bucket we're not adding the node to isn't empty. if (other->second->is_in_range(node->id())) { diff --git a/libtorrent/src/dht/dht_tracker.cc b/libtorrent/src/dht/dht_tracker.cc index 3636551a..a5ffa24c 100644 --- a/libtorrent/src/dht/dht_tracker.cc +++ b/libtorrent/src/dht/dht_tracker.cc @@ -67,7 +67,7 @@ DhtTracker::add_peer(uint32_t addr, uint16_t port) { // If peer doesn't exist, append to list if the table is not full. if (size() < max_size) { - m_peers.push_back(compact); + m_peers.emplace_back(compact); m_lastSeen.push_back(cachedTime.seconds()); // Peer doesn't exist and table is full: replace oldest peer. diff --git a/libtorrent/src/dht/dht_transaction.cc b/libtorrent/src/dht/dht_transaction.cc index 84ffc175..13e7e7af 100644 --- a/libtorrent/src/dht/dht_transaction.cc +++ b/libtorrent/src/dht/dht_transaction.cc @@ -76,7 +76,7 @@ DhtSearch::~DhtSearch() { bool DhtSearch::add_contact(const HashString& id, const rak::socket_address* sa) { DhtNode* n = new DhtNode(id, sa); - bool added = insert(std::make_pair(n, this)).second; + bool added = emplace(n, this).second; if (!added) delete n; diff --git a/libtorrent/src/download/download_constructor.cc b/libtorrent/src/download/download_constructor.cc index 1bf362fa..5867c8b1 100644 --- a/libtorrent/src/download/download_constructor.cc +++ b/libtorrent/src/download/download_constructor.cc @@ -109,14 +109,14 @@ DownloadConstructor::parse_name(const Object& b) { std::list pathList; - pathList.push_back(Path()); + pathList.emplace_back(); pathList.back().set_encoding(m_defaultEncoding); pathList.back().push_back(b.get_key_string("name")); for (Object::map_const_iterator itr = b.as_map().begin(); (itr = std::find_if(itr, b.as_map().end(), download_constructor_is_single_path())) != b.as_map().end(); ++itr) { - pathList.push_back(Path()); + pathList.emplace_back(); pathList.back().set_encoding(itr->first.substr(sizeof("name.") - 1)); pathList.back().push_back(itr->second.as_string()); } @@ -269,14 +269,14 @@ DownloadConstructor::parse_single_file(const Object& b, uint32_t chunkSize) { std::list pathList; - pathList.push_back(Path()); + pathList.emplace_back(); pathList.back().set_encoding(m_defaultEncoding); pathList.back().push_back(b.get_key_string("name")); for (Object::map_const_iterator itr = b.as_map().begin(); (itr = std::find_if(itr, b.as_map().end(), download_constructor_is_single_path())) != b.as_map().end(); ++itr) { - pathList.push_back(Path()); + pathList.emplace_back(); pathList.back().set_encoding(itr->first.substr(sizeof("name.") - 1)); pathList.back().push_back(itr->second.as_string()); } diff --git a/libtorrent/src/download/download_main.cc b/libtorrent/src/download/download_main.cc index 201c3e52..fb58695a 100644 --- a/libtorrent/src/download/download_main.cc +++ b/libtorrent/src/download/download_main.cc @@ -404,7 +404,7 @@ DownloadMain::do_peer_exchange() { const rak::socket_address* sa = rak::socket_address::cast_from(pcb->peer_info()->socket_address()); if (pcb->peer_info()->listen_port() != 0 && sa->family() == rak::socket_address::af_inet) - current.push_back(SocketAddressCompact(sa->sa_inet()->address_n(), htons(pcb->peer_info()->listen_port()))); + current.emplace_back(sa->sa_inet()->address_n(), htons(pcb->peer_info()->listen_port())); if (!pcb->extensions()->is_remote_supported(ProtocolExtension::UT_PEX)) continue; diff --git a/libtorrent/src/download/download_wrapper.cc b/libtorrent/src/download/download_wrapper.cc index 66935491..05a1254e 100644 --- a/libtorrent/src/download/download_wrapper.cc +++ b/libtorrent/src/download/download_wrapper.cc @@ -230,9 +230,9 @@ DownloadWrapper::receive_hash_done(ChunkHandle handle, const char* hash) { } if (!m_main->have_queue()->empty() && m_main->have_queue()->front().first >= cachedTime) - m_main->have_queue()->push_front(DownloadMain::have_queue_type::value_type(m_main->have_queue()->front().first + 1, handle.index())); + m_main->have_queue()->emplace_front(m_main->have_queue()->front().first + 1, handle.index()); else - m_main->have_queue()->push_front(DownloadMain::have_queue_type::value_type(cachedTime, handle.index())); + m_main->have_queue()->emplace_front(cachedTime, handle.index()); } else { // This needs to ensure the chunk is still valid. diff --git a/libtorrent/src/torrent/data/block_transfer.h b/libtorrent/src/torrent/data/block_transfer.h index b450db26..053298f8 100644 --- a/libtorrent/src/torrent/data/block_transfer.h +++ b/libtorrent/src/torrent/data/block_transfer.h @@ -72,7 +72,7 @@ class LIBTORRENT_EXPORT BlockTransfer { bool is_finished() const { return m_position == m_piece.length(); } key_type peer_info() { return m_peer_info; } - const key_type const_peer_info() const { return m_peer_info; } + key_type const_peer_info() const { return m_peer_info; } Block* block() { return m_block; } const Block* const_block() const { return m_block; } diff --git a/libtorrent/src/torrent/data/transfer_list.cc b/libtorrent/src/torrent/data/transfer_list.cc index 74463c82..c28b12a4 100644 --- a/libtorrent/src/torrent/data/transfer_list.cc +++ b/libtorrent/src/torrent/data/transfer_list.cc @@ -143,7 +143,7 @@ TransferList::hash_succeeded(uint32_t index, Chunk* chunk) { // pruned every 60 minutes, so any timer that reads values once // every 30 minutes is guaranteed to get them all as long as it is // ordered properly. - m_completedList.push_back(std::make_pair(rak::timer::current().usec(), index)); + m_completedList.emplace_back(rak::timer::current().usec(), index); if (rak::timer(m_completedList.front().first) + rak::timer::from_minutes(60) < rak::timer::current()) { completed_list_type::iterator itr = std::find_if(m_completedList.begin(), m_completedList.end(), @@ -226,7 +226,7 @@ TransferList::update_failed(BlockList* blockList, Chunk* chunk) { chunk->to_buffer(buffer, itr->piece().offset(), itr->piece().length()); - itr->failed_list()->push_back(BlockFailed::value_type(buffer, 1)); + itr->failed_list()->emplace_back(buffer, 1); failedItr = itr->failed_list()->end() - 1; // Count how many new data sets? diff --git a/libtorrent/src/torrent/download/group_entry.h b/libtorrent/src/torrent/download/group_entry.h index e167ecbb..48becaff 100644 --- a/libtorrent/src/torrent/download/group_entry.h +++ b/libtorrent/src/torrent/download/group_entry.h @@ -108,7 +108,7 @@ inline void group_entry::connection_unchoked(PeerConnectionBase* pcb) { if (itr != m_unchoked.end()) throw internal_error("group_entry::connection_unchoked(pcb) failed."); - m_unchoked.push_back(weighted_connection(pcb, uint32_t())); + m_unchoked.emplace_back(pcb, uint32_t()); } inline void group_entry::connection_queued(PeerConnectionBase* pcb) { @@ -117,7 +117,7 @@ inline void group_entry::connection_queued(PeerConnectionBase* pcb) { if (itr != m_queued.end()) throw internal_error("group_entry::connection_queued(pcb) failed."); - m_queued.push_back(weighted_connection(pcb, uint32_t())); + m_queued.emplace_back(pcb, uint32_t()); } inline void diff --git a/libtorrent/src/torrent/rate.cc b/libtorrent/src/torrent/rate.cc index 65086ee8..cd1f517e 100644 --- a/libtorrent/src/torrent/rate.cc +++ b/libtorrent/src/torrent/rate.cc @@ -65,7 +65,7 @@ Rate::insert(rate_type bytes) { throw internal_error("Rate::insert(bytes) received out-of-bounds values.."); if (m_container.empty() || m_container.front().first != cachedTime.seconds()) - m_container.push_front(value_type(cachedTime.seconds(), bytes)); + m_container.emplace_front(cachedTime.seconds(), bytes); else m_container.front().second += bytes; diff --git a/libtorrent/src/torrent/torrent.cc b/libtorrent/src/torrent/torrent.cc index 62eda0da..4d85249c 100644 --- a/libtorrent/src/torrent/torrent.cc +++ b/libtorrent/src/torrent/torrent.cc @@ -221,7 +221,7 @@ void download_list(DList& dlist) { for (DownloadManager::const_iterator itr = manager->download_manager()->begin(); itr != manager->download_manager()->end(); ++itr) - dlist.push_back(Download(*itr)); + dlist.emplace_back(*itr); } // Make sure you check that it's valid. diff --git a/libtorrent/src/torrent/utils/log.cc b/libtorrent/src/torrent/utils/log.cc index 2909141f..812cc23c 100644 --- a/libtorrent/src/torrent/utils/log.cc +++ b/libtorrent/src/torrent/utils/log.cc @@ -209,22 +209,22 @@ log_group::internal_print(const HashString* hash, const char* subsystem, const v } #define LOG_CASCADE(parent) LOG_CHILDREN_CASCADE(parent, parent) -#define LOG_LINK(parent, child) log_children.push_back(std::make_pair(parent, child)) +#define LOG_LINK(parent, child) log_children.emplace_back(parent, child) #define LOG_CHILDREN_CASCADE(parent, subgroup) \ - log_children.push_back(std::make_pair(parent + LOG_ERROR, subgroup + LOG_CRITICAL)); \ - log_children.push_back(std::make_pair(parent + LOG_WARN, subgroup + LOG_ERROR)); \ - log_children.push_back(std::make_pair(parent + LOG_NOTICE, subgroup + LOG_WARN)); \ - log_children.push_back(std::make_pair(parent + LOG_INFO, subgroup + LOG_NOTICE)); \ - log_children.push_back(std::make_pair(parent + LOG_DEBUG, subgroup + LOG_INFO)); + log_children.emplace_back(parent + LOG_ERROR, subgroup + LOG_CRITICAL); \ + log_children.emplace_back(parent + LOG_WARN, subgroup + LOG_ERROR); \ + log_children.emplace_back(parent + LOG_NOTICE, subgroup + LOG_WARN); \ + log_children.emplace_back(parent + LOG_INFO, subgroup + LOG_NOTICE); \ + log_children.emplace_back(parent + LOG_DEBUG, subgroup + LOG_INFO); #define LOG_CHILDREN_SUBGROUP(parent, subgroup) \ - log_children.push_back(std::make_pair(parent + LOG_CRITICAL, subgroup + LOG_CRITICAL)); \ - log_children.push_back(std::make_pair(parent + LOG_ERROR, subgroup + LOG_ERROR)); \ - log_children.push_back(std::make_pair(parent + LOG_WARN, subgroup + LOG_WARN)); \ - log_children.push_back(std::make_pair(parent + LOG_NOTICE, subgroup + LOG_NOTICE)); \ - log_children.push_back(std::make_pair(parent + LOG_INFO, subgroup + LOG_INFO)); \ - log_children.push_back(std::make_pair(parent + LOG_DEBUG, subgroup + LOG_DEBUG)); + log_children.emplace_back(parent + LOG_CRITICAL, subgroup + LOG_CRITICAL); \ + log_children.emplace_back(parent + LOG_ERROR, subgroup + LOG_ERROR); \ + log_children.emplace_back(parent + LOG_WARN, subgroup + LOG_WARN); \ + log_children.emplace_back(parent + LOG_NOTICE, subgroup + LOG_NOTICE); \ + log_children.emplace_back(parent + LOG_INFO, subgroup + LOG_INFO); \ + log_children.emplace_back(parent + LOG_DEBUG, subgroup + LOG_DEBUG); void log_initialize() { @@ -301,7 +301,7 @@ log_open_output(const char* name, log_slot slot) { log_output_list::iterator itr = log_find_output_name(name); if (itr == log_outputs.end()) { - log_outputs.push_back(std::make_pair(name, slot)); + log_outputs.emplace_back(name, slot); } else { // by replacing the "write" slot binding, the old file gets closed // (handles are shared pointers) @@ -360,7 +360,7 @@ log_add_child(int group, int child) { if (std::find(log_children.begin(), log_children.end(), std::make_pair(group, child)) != log_children.end()) return; - log_children.push_back(std::make_pair(group, child)); + log_children.emplace_back(group, child); std::sort(log_children.begin(), log_children.end()); log_rebuild_cache(); diff --git a/libtorrent/src/torrent/utils/option_strings.cc b/libtorrent/src/torrent/utils/option_strings.cc index 246254dd..d3dd2acd 100644 --- a/libtorrent/src/torrent/utils/option_strings.cc +++ b/libtorrent/src/torrent/utils/option_strings.cc @@ -296,12 +296,12 @@ option_list_strings(option_enum opt_enum) { option_pair* itr = option_pair_lists[opt_enum]; while (itr->name != NULL) - result.push_back(std::string(itr++->name)); + result.emplace_back(std::string(itr++->name)); } else if (opt_enum < OPTION_MAX_SIZE) { const char** itr = option_single_lists[opt_enum - OPTION_START_COMPACT].name; - while (*itr != NULL) result.push_back(std::string(*itr++)); + while (*itr != NULL) result.emplace_back(std::string(*itr++)); } return Object::from_list(result); diff --git a/libtorrent/src/tracker/tracker_http.cc b/libtorrent/src/tracker/tracker_http.cc index 1bf94107..e3abef14 100644 --- a/libtorrent/src/tracker/tracker_http.cc +++ b/libtorrent/src/tracker/tracker_http.cc @@ -73,8 +73,8 @@ TrackerHttp::TrackerHttp(TrackerList* parent, const std::string& url, int flags) m_get(Http::slot_factory()()), m_data(NULL) { - m_get->signal_done().push_back(std::bind(&TrackerHttp::receive_done, this)); - m_get->signal_failed().push_back(std::bind(&TrackerHttp::receive_failed, this, std::placeholders::_1)); + m_get->signal_done().emplace_back(std::bind(&TrackerHttp::receive_done, this)); + m_get->signal_failed().emplace_back(std::bind(&TrackerHttp::receive_failed, this, std::placeholders::_1)); // Haven't considered if this needs any stronger error detection, // can dropping the '?' be used for malicious purposes?