From eae1ed336423f5268ea38a644695185c8d2fb6e3 Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Mon, 28 Mar 2022 21:40:49 +0200 Subject: [PATCH] Don't construct property builder unnecessarily --- mqttpacket.cpp | 4 ++-- types.cpp | 5 +++++ types.h | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mqttpacket.cpp b/mqttpacket.cpp index 6ed226c..9d6f0c5 100644 --- a/mqttpacket.cpp +++ b/mqttpacket.cpp @@ -133,8 +133,8 @@ MqttPacket::MqttPacket(const ProtocolVersion protocolVersion, const Publish &_pu if (protocolVersion >= ProtocolVersion::Mqtt5) { - // Step 1: make certain properties available as objects, because FlashMQ needs access to them for internal logic. - if (_publish.propertyBuilder) // TODO: only do this when there are user properties. Otherwise we don't need it. + // Step 1: make certain properties available as objects, because FlashMQ needs access to them for internal logic (only ACL checking at this point). + if (_publish.hasUserProperties()) { this->publishData.constructPropertyBuilder(); this->publishData.propertyBuilder->setNewUserProperties(_publish.propertyBuilder->getUserProperties()); diff --git a/types.cpp b/types.cpp index 76b88eb..03f69e4 100644 --- a/types.cpp +++ b/types.cpp @@ -159,6 +159,11 @@ void PublishBase::constructPropertyBuilder() this->propertyBuilder = std::make_shared(); } +bool PublishBase::hasUserProperties() const +{ + return this->propertyBuilder.operator bool() && this->propertyBuilder->getUserProperties().operator bool(); +} + Publish::Publish(const Publish &other) : PublishBase(other) { diff --git a/types.h b/types.h index 6c7de0c..d459411 100644 --- a/types.h +++ b/types.h @@ -215,6 +215,7 @@ public: size_t getLengthWithoutFixedHeader() const; void setClientSpecificProperties(); void constructPropertyBuilder(); + bool hasUserProperties() const; }; class Publish : public PublishBase -- libgit2 0.21.4