Commit eae1ed336423f5268ea38a644695185c8d2fb6e3
1 parent
3022c275
Don't construct property builder unnecessarily
Showing
3 changed files
with
8 additions
and
2 deletions
mqttpacket.cpp
| @@ -133,8 +133,8 @@ MqttPacket::MqttPacket(const ProtocolVersion protocolVersion, const Publish &_pu | @@ -133,8 +133,8 @@ MqttPacket::MqttPacket(const ProtocolVersion protocolVersion, const Publish &_pu | ||
| 133 | 133 | ||
| 134 | if (protocolVersion >= ProtocolVersion::Mqtt5) | 134 | if (protocolVersion >= ProtocolVersion::Mqtt5) |
| 135 | { | 135 | { |
| 136 | - // Step 1: make certain properties available as objects, because FlashMQ needs access to them for internal logic. | ||
| 137 | - if (_publish.propertyBuilder) // TODO: only do this when there are user properties. Otherwise we don't need it. | 136 | + // Step 1: make certain properties available as objects, because FlashMQ needs access to them for internal logic (only ACL checking at this point). |
| 137 | + if (_publish.hasUserProperties()) | ||
| 138 | { | 138 | { |
| 139 | this->publishData.constructPropertyBuilder(); | 139 | this->publishData.constructPropertyBuilder(); |
| 140 | this->publishData.propertyBuilder->setNewUserProperties(_publish.propertyBuilder->getUserProperties()); | 140 | this->publishData.propertyBuilder->setNewUserProperties(_publish.propertyBuilder->getUserProperties()); |
types.cpp
| @@ -159,6 +159,11 @@ void PublishBase::constructPropertyBuilder() | @@ -159,6 +159,11 @@ void PublishBase::constructPropertyBuilder() | ||
| 159 | this->propertyBuilder = std::make_shared<Mqtt5PropertyBuilder>(); | 159 | this->propertyBuilder = std::make_shared<Mqtt5PropertyBuilder>(); |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | +bool PublishBase::hasUserProperties() const | ||
| 163 | +{ | ||
| 164 | + return this->propertyBuilder.operator bool() && this->propertyBuilder->getUserProperties().operator bool(); | ||
| 165 | +} | ||
| 166 | + | ||
| 162 | Publish::Publish(const Publish &other) : | 167 | Publish::Publish(const Publish &other) : |
| 163 | PublishBase(other) | 168 | PublishBase(other) |
| 164 | { | 169 | { |
types.h
| @@ -215,6 +215,7 @@ public: | @@ -215,6 +215,7 @@ public: | ||
| 215 | size_t getLengthWithoutFixedHeader() const; | 215 | size_t getLengthWithoutFixedHeader() const; |
| 216 | void setClientSpecificProperties(); | 216 | void setClientSpecificProperties(); |
| 217 | void constructPropertyBuilder(); | 217 | void constructPropertyBuilder(); |
| 218 | + bool hasUserProperties() const; | ||
| 218 | }; | 219 | }; |
| 219 | 220 | ||
| 220 | class Publish : public PublishBase | 221 | class Publish : public PublishBase |