From fc29297d871d2589c5fcd5151e2ccbc58b342dad Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 19 Aug 2015 10:55:26 -0700 Subject: [PATCH] Update SendQueue::queuePacketList to use splice --- libraries/networking/src/udt/SendQueue.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index 650542dec5..0e97e9a1e0 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -68,20 +68,19 @@ void SendQueue::queuePacketList(std::unique_ptr packetList) { Q_ASSERT(packetList->_packets.size() > 0); { - QWriteLocker locker(&_packetsLock); - auto messageNumber = getNextMessageNumber(); if (packetList->_packets.size() == 1) { - auto packet = packetList->takeFront(); - packet->setPacketPosition(Packet::PacketPosition::ONLY); + auto packet = packetList->_packets.front().get(); + packet->setPacketPosition(Packet::PacketPosition::ONLY); packet->writeMessageNumber(messageNumber); - _packets.push_back(std::move(packet)); } else { bool haveMarkedFirstPacket = false; - while (!packetList->_packets.empty()) { - auto packet = packetList->takeFront(); + auto end = packetList->_packets.end(); + for (auto it = packetList->_packets.begin(); it != end; ++it) { + auto packet = it->get(); + if (!haveMarkedFirstPacket) { packet->setPacketPosition(Packet::PacketPosition::FIRST); haveMarkedFirstPacket = true; @@ -92,11 +91,14 @@ void SendQueue::queuePacketList(std::unique_ptr packetList) { } packet->writeMessageNumber(messageNumber); - - _packets.push_back(std::move(packet)); } } + + QWriteLocker locker(&_packetsLock); + + _packets.splice(_packets.end(), packetList->_packets); } + if (!this->thread()->isRunning()) { this->thread()->start(); }