forked from premiere/premiere-libtorrent
use move to avoid heap allocating the vector when posting watermark_callback (#700)
This commit is contained in:
parent
6cf5ac9dd1
commit
64409dae65
|
@ -67,17 +67,12 @@ namespace libtorrent
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// this is posted to the network thread
|
// this is posted to the network thread
|
||||||
void watermark_callback(std::vector<boost::weak_ptr<disk_observer> >* cbs)
|
void watermark_callback(std::vector<boost::weak_ptr<disk_observer>> const& cbs)
|
||||||
{
|
{
|
||||||
if (cbs != NULL)
|
for (auto const& i : cbs)
|
||||||
{
|
{
|
||||||
for (std::vector<boost::weak_ptr<disk_observer> >::iterator i = cbs->begin()
|
boost::shared_ptr<disk_observer> o = i.lock();
|
||||||
, end(cbs->end()); i != end; ++i)
|
if (o) o->on_disk();
|
||||||
{
|
|
||||||
boost::shared_ptr<disk_observer> o = i->lock();
|
|
||||||
if (o) o->on_disk();
|
|
||||||
}
|
|
||||||
delete cbs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,11 +154,10 @@ namespace libtorrent
|
||||||
|
|
||||||
m_exceeded_max_size = false;
|
m_exceeded_max_size = false;
|
||||||
|
|
||||||
std::vector<boost::weak_ptr<disk_observer> >* cbs
|
std::vector<boost::weak_ptr<disk_observer>> cbs;
|
||||||
= new std::vector<boost::weak_ptr<disk_observer> >();
|
m_observers.swap(cbs);
|
||||||
m_observers.swap(*cbs);
|
|
||||||
l.unlock();
|
l.unlock();
|
||||||
m_ios.post(boost::bind(&watermark_callback, cbs));
|
m_ios.post(std::bind(&watermark_callback, std::move(cbs)));
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TORRENT_USE_ASSERTS
|
#if TORRENT_USE_ASSERTS
|
||||||
|
|
Loading…
Reference in New Issue