Commit eae1ed336423f5268ea38a644695185c8d2fb6e3

Authored by Wiebe Cazemier
1 parent 3022c275

Don't construct property builder unnecessarily

mqttpacket.cpp
... ... @@ -133,8 +133,8 @@ MqttPacket::MqttPacket(const ProtocolVersion protocolVersion, const Publish &_pu
133 133  
134 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 139 this->publishData.constructPropertyBuilder();
140 140 this->publishData.propertyBuilder->setNewUserProperties(_publish.propertyBuilder->getUserProperties());
... ...
types.cpp
... ... @@ -159,6 +159,11 @@ void PublishBase::constructPropertyBuilder()
159 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 167 Publish::Publish(const Publish &other) :
163 168 PublishBase(other)
164 169 {
... ...
... ... @@ -215,6 +215,7 @@ public:
215 215 size_t getLengthWithoutFixedHeader() const;
216 216 void setClientSpecificProperties();
217 217 void constructPropertyBuilder();
  218 + bool hasUserProperties() const;
218 219 };
219 220  
220 221 class Publish : public PublishBase
... ...