From bd9b42bd4cbb4fc4f8ff48d65c41a7875274227b Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 9 Jul 2015 11:23:44 -0700 Subject: [PATCH] change createCopy in packet to take const & --- libraries/networking/src/NLPacket.cpp | 9 ++++----- libraries/networking/src/NLPacket.h | 2 +- libraries/networking/src/Packet.cpp | 5 ++--- libraries/networking/src/Packet.h | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/libraries/networking/src/NLPacket.cpp b/libraries/networking/src/NLPacket.cpp index f61b47b4b2..f125cdc6b7 100644 --- a/libraries/networking/src/NLPacket.cpp +++ b/libraries/networking/src/NLPacket.cpp @@ -33,13 +33,12 @@ std::unique_ptr NLPacket::create(PacketType::Value type, int64_t size) if (size > maxPayloadSize(type)) { return std::unique_ptr(); } - + return std::unique_ptr(new NLPacket(type, size)); } -std::unique_ptr NLPacket::createCopy(const std::unique_ptr& other) { - Q_ASSERT(other); - return std::unique_ptr(new NLPacket(*other)); +std::unique_ptr NLPacket::createCopy(const NLPacket& other) { + return std::unique_ptr(new NLPacket(other)); } NLPacket::NLPacket(PacketType::Value type, int64_t size) : Packet(type, localHeaderSize(type) + size) { @@ -59,4 +58,4 @@ void NLPacket::setConnectionUuid(QUuid connectionUuid) { auto offset = Packet::totalHeadersSize() + ((NON_SOURCED_PACKETS.contains(_type)) ? 0 : NUM_BYTES_RFC4122_UUID); memcpy(_packet.get() + offset, connectionUuid.toRfc4122().constData(), NUM_BYTES_RFC4122_UUID); -} \ No newline at end of file +} diff --git a/libraries/networking/src/NLPacket.h b/libraries/networking/src/NLPacket.h index 744056c103..7ea449815b 100644 --- a/libraries/networking/src/NLPacket.h +++ b/libraries/networking/src/NLPacket.h @@ -19,7 +19,7 @@ class NLPacket : public Packet { public: static std::unique_ptr create(PacketType::Value type, int64_t size = -1); // Provided for convenience, try to limit use - static std::unique_ptr createCopy(const std::unique_ptr& other); + static std::unique_ptr createCopy(const NLPacket& other); static int64_t localHeaderSize(PacketType::Value type); static int64_t maxPayloadSize(PacketType::Value type); diff --git a/libraries/networking/src/Packet.cpp b/libraries/networking/src/Packet.cpp index aa0b407398..6d585ac4aa 100644 --- a/libraries/networking/src/Packet.cpp +++ b/libraries/networking/src/Packet.cpp @@ -38,9 +38,8 @@ std::unique_ptr Packet::create(PacketType::Value type, qint64 size) { return std::unique_ptr(new Packet(type, size)); } -std::unique_ptr Packet::createCopy(const std::unique_ptr& other) { - Q_ASSERT(other); - return std::unique_ptr(new Packet(*other)); +std::unique_ptr Packet::createCopy(const Packet& other) { + return std::unique_ptr(new Packet(other)); } qint64 Packet::totalHeadersSize() const { diff --git a/libraries/networking/src/Packet.h b/libraries/networking/src/Packet.h index 7bd8d81194..1de17602da 100644 --- a/libraries/networking/src/Packet.h +++ b/libraries/networking/src/Packet.h @@ -25,7 +25,7 @@ public: static std::unique_ptr create(PacketType::Value type, int64_t size = -1); // Provided for convenience, try to limit use - static std::unique_ptr createCopy(const std::unique_ptr& other); + static std::unique_ptr createCopy(const Packet& other); static qint64 localHeaderSize(PacketType::Value type); static qint64 maxPayloadSize(PacketType::Value type);