use std::unordered_maps in OctreeEditPacketSender

This commit is contained in:
Stephen Birarda 2015-07-08 14:52:14 -07:00
parent 59484fc3cf
commit 9fb43b71d4
2 changed files with 18 additions and 11 deletions

View file

@ -296,10 +296,10 @@ void OctreeEditPacketSender::releaseQueuedMessages() {
std::unique_ptr<NLPacket> releasedPacket;
// swap the null ptr with the packet we want to release
i.value().swap(releasedPacket);
i->second.swap(releasedPacket);
// move and release the queued packet
releaseQueuedPacket(i.key(), std::move(releasedPacket));
releaseQueuedPacket(i->first, std::move(releasedPacket));
}
_packetsQueueLock.unlock();
}
@ -342,10 +342,10 @@ void OctreeEditPacketSender::processNackPacket(const QByteArray& packet) {
QUuid sendingNodeUUID = uuidFromPacketHeader(packet);
// if packet history doesn't exist for the sender node (somehow), bail
if (!_sentPacketHistories.contains(sendingNodeUUID)) {
if (_sentPacketHistories.count(sendingNodeUUID) == 0) {
return;
}
const SentPacketHistory& sentPacketHistory = _sentPacketHistories.value(sendingNodeUUID);
const SentPacketHistory& sentPacketHistory = _sentPacketHistories[sendingNodeUUID];
// TODO: these NAK packets no longer send the number of sequence numbers - just read out sequence numbers in blocks
@ -373,7 +373,7 @@ void OctreeEditPacketSender::processNackPacket(const QByteArray& packet) {
void OctreeEditPacketSender::nodeKilled(SharedNodePointer node) {
// TODO: add locks
QUuid nodeUUID = node->getUUID();
_pendingEditPackets.remove(nodeUUID);
_outgoingSequenceNumbers.remove(nodeUUID);
_sentPacketHistories.remove(nodeUUID);
_pendingEditPackets.erase(nodeUUID);
_outgoingSequenceNumbers.erase(nodeUUID);
_sentPacketHistories.erase(nodeUUID);
}

View file

@ -12,13 +12,20 @@
#ifndef hifi_OctreeEditPacketSender_h
#define hifi_OctreeEditPacketSender_h
#include <qqueue.h>
#include <PacketSender.h>
#include <PacketHeaders.h>
#include "JurisdictionMap.h"
#include "SentPacketHistory.h"
namespace std {
template <> struct hash<QUuid> {
size_t operator()(const QUuid& uuid) const {
return qHash(uuid);
}
};
}
/// Utility for processing, packing, queueing and sending of outbound edit messages.
class OctreeEditPacketSender : public PacketSender {
Q_OBJECT
@ -94,7 +101,7 @@ protected:
void processPreServerExistsPackets();
// These are packets which are destined from know servers but haven't been released because they're still too small
QHash<QUuid, std::unique_ptr<NLPacket>> _pendingEditPackets;
std::unordered_map<QUuid, std::unique_ptr<NLPacket>> _pendingEditPackets;
// These are packets that are waiting to be processed because we don't yet know if there are servers
int _maxPendingMessages;
@ -109,7 +116,7 @@ protected:
QMutex _releaseQueuedPacketMutex;
// TODO: add locks for this and _pendingEditPackets
QHash<QUuid, SentPacketHistory> _sentPacketHistories;
QHash<QUuid, quint16> _outgoingSequenceNumbers;
std::unordered_map<QUuid, SentPacketHistory> _sentPacketHistories;
std::unordered_map<QUuid, quint16> _outgoingSequenceNumbers;
};
#endif // hifi_OctreeEditPacketSender_h