From 64409dae651ca334facca52247875ce2746884bb Mon Sep 17 00:00:00 2001 From: Steven Siloti Date: Fri, 6 May 2016 21:55:38 -0700 Subject: [PATCH] use move to avoid heap allocating the vector when posting watermark_callback (#700) --- src/disk_buffer_pool.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/disk_buffer_pool.cpp b/src/disk_buffer_pool.cpp index 73964a062..8642e1506 100644 --- a/src/disk_buffer_pool.cpp +++ b/src/disk_buffer_pool.cpp @@ -67,17 +67,12 @@ namespace libtorrent namespace { // this is posted to the network thread - void watermark_callback(std::vector >* cbs) + void watermark_callback(std::vector> const& cbs) { - if (cbs != NULL) + for (auto const& i : cbs) { - for (std::vector >::iterator i = cbs->begin() - , end(cbs->end()); i != end; ++i) - { - boost::shared_ptr o = i->lock(); - if (o) o->on_disk(); - } - delete cbs; + boost::shared_ptr o = i.lock(); + if (o) o->on_disk(); } } @@ -159,11 +154,10 @@ namespace libtorrent m_exceeded_max_size = false; - std::vector >* cbs - = new std::vector >(); - m_observers.swap(*cbs); + std::vector> cbs; + m_observers.swap(cbs); l.unlock(); - m_ios.post(boost::bind(&watermark_callback, cbs)); + m_ios.post(std::bind(&watermark_callback, std::move(cbs))); } #if TORRENT_USE_ASSERTS