diff --git a/.clang-tidy b/.clang-tidy index d89f07b2..aa78ee99 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,6 +5,7 @@ modernize-*, performance-*, -bugprone-easily-swappable-parameters, + -bugprone-forward-declaration-namespace, -clang-analyzer-cplusplus.NewDeleteLeaks, -clang-analyzer-security.insecureAPI.rand, -clang-analyzer-webkit*, diff --git a/bindings/python/_broker.cpp b/bindings/python/_broker.cpp index 3f87c8dd..9d801f7e 100644 --- a/bindings/python/_broker.cpp +++ b/bindings/python/_broker.cpp @@ -393,11 +393,13 @@ PYBIND11_MODULE(_broker, m) { .def("peers", &broker::endpoint::peers) .def("peer_subscriptions", &broker::endpoint::peer_subscriptions) .def("forward", &broker::endpoint::forward) - .def("publish", (void(broker::endpoint::*)(broker::topic, broker::data)) - & broker::endpoint::publish) - .def("publish", (void(broker::endpoint::*)(const broker::endpoint_info&, - broker::topic, broker::data)) - & broker::endpoint::publish) + .def("publish", + (void(broker::endpoint::*)(broker::topic, const broker::data&)) + & broker::endpoint::publish) + .def("publish", + (void(broker::endpoint::*)(const broker::endpoint_info&, broker::topic, + const broker::data&)) + & broker::endpoint::publish) .def("publish_batch", [](broker::endpoint& ep, std::vector batch) { for (auto& item : batch) diff --git a/include/broker/endpoint.hh b/include/broker/endpoint.hh index 70400b26..bad97a68 100644 --- a/include/broker/endpoint.hh +++ b/include/broker/endpoint.hh @@ -256,7 +256,7 @@ public: /// Publishes a message. /// @param t The topic of the message. /// @param d The message data. - void publish(topic t, data d); + void publish(topic t, const data& d); /// Publishes a message. /// @param t The topic of the message. @@ -286,7 +286,7 @@ public: /// @param dst The destination endpoint. /// @param t The topic of the message. /// @param d The message data. - void publish(const endpoint_info& dst, topic t, data d); + void publish(const endpoint_info& dst, topic t, const data& d); /// Publishes a message to a specific peer endpoint only. /// @param dst The destination endpoint. diff --git a/include/broker/publisher.hh b/include/broker/publisher.hh index 04dc83aa..36a40596 100644 --- a/include/broker/publisher.hh +++ b/include/broker/publisher.hh @@ -73,7 +73,7 @@ public: void publish(const data& x); /// Sends `xs` to all subscribers. - void publish(std::vector xs); + void publish(const std::vector& xs); /// Sends `x` to all subscribers. void publish(set_builder&& x); diff --git a/include/broker/topic.hh b/include/broker/topic.hh index fc21c5b9..105d3e33 100644 --- a/include/broker/topic.hh +++ b/include/broker/topic.hh @@ -54,6 +54,14 @@ public: /// Default-constructs an empty topic. topic() = default; + topic(const topic&) = default; + + topic(topic&&) noexcept = default; + + topic& operator=(const topic&) = default; + + topic& operator=(topic&&) noexcept = default; + /// Constructs a topic from a type that is convertible to a string. /// @param x A value convertible to a string. template find(*key->raw()), envelope_.get()}; } - variant operator[](const variant& key) const noexcept { + variant operator[](const variant& key) const { if (auto i = values_->find(*key.raw()); i != values_->end()) return variant{std::addressof(i->second), envelope_}; return variant{}; } - variant operator[](std::string_view key) const noexcept { + variant operator[](std::string_view key) const { return do_lookup(key); } private: template - variant do_lookup(T key) const noexcept { + variant do_lookup(T key) const { if (values_ == nullptr) return variant{}; auto key_view = variant_data{key}; diff --git a/include/broker/zeek.hh b/include/broker/zeek.hh index 5cef066c..f28c7a97 100644 --- a/include/broker/zeek.hh +++ b/include/broker/zeek.hh @@ -134,7 +134,7 @@ public: explicit Invalid(variant msg) : Message(std::move(msg)) {} - explicit Invalid(data_message msg) : Invalid(broker::get_data(msg)) {} + explicit Invalid(const data_message& msg) : Invalid(broker::get_data(msg)) {} explicit Invalid(Message&& msg) : Message(std::move(msg)) {} }; @@ -270,7 +270,7 @@ public: explicit Event(variant msg) : Message(std::move(msg)) {} - explicit Event(data_message msg) : Message(broker::get_data(msg)) {} + explicit Event(const data_message& msg) : Message(broker::get_data(msg)) {} std::string_view name() const { auto&& fields = sub_fields(); @@ -369,7 +369,8 @@ public: explicit LogCreate(variant msg) : Message(std::move(msg)) {} - explicit LogCreate(data_message msg) : LogCreate(broker::move_data(msg)) {} + explicit LogCreate(const data_message& msg) + : LogCreate(broker::move_data(msg)) {} enum_value_view stream_id() const { auto&& fields = sub_fields(); @@ -432,7 +433,8 @@ public: explicit LogWrite(variant msg) : Message(std::move(msg)) {} - explicit LogWrite(data_message msg) : LogWrite(broker::move_data(msg)) {} + explicit LogWrite(const data_message& msg) + : LogWrite(broker::move_data(msg)) {} enum_value_view stream_id() const { auto&& fields = sub_fields(); @@ -485,7 +487,7 @@ public: explicit IdentifierUpdate(variant msg) : Message(std::move(msg)) {} - explicit IdentifierUpdate(data_message msg) + explicit IdentifierUpdate(const data_message& msg) : IdentifierUpdate(broker::move_data(msg)) {} std::string_view id_name() const { @@ -512,7 +514,7 @@ class Batch : public Message { public: explicit Batch(variant msg); - explicit Batch(data_message msg) : Batch(broker::get_data(msg)) {} + explicit Batch(const data_message& msg) : Batch(broker::get_data(msg)) {} size_t size() const noexcept { return impl_ ? impl_->size() : 0; @@ -570,7 +572,7 @@ private: }; template -auto visit_as_message(F&& f, broker::data_message msg) { +auto visit_as_message(F&& f, const broker::data_message& msg) { auto do_visit = [&f](auto& tmp) { if (tmp.valid()) return f(tmp); @@ -579,27 +581,27 @@ auto visit_as_message(F&& f, broker::data_message msg) { }; switch (Message::type(msg)) { default: { - Invalid tmp{std::move(msg)}; + Invalid tmp{msg}; return f(tmp); } case Message::Type::Event: { - Event tmp{std::move(msg)}; + Event tmp{msg}; return do_visit(tmp); } case Message::Type::LogCreate: { - LogCreate tmp{std::move(msg)}; + LogCreate tmp{msg}; return do_visit(tmp); } case Message::Type::LogWrite: { - LogWrite tmp{std::move(msg)}; + LogWrite tmp{msg}; return do_visit(tmp); } case Message::Type::IdentifierUpdate: { - IdentifierUpdate tmp{std::move(msg)}; + IdentifierUpdate tmp{msg}; return do_visit(tmp); } case Message::Type::Batch: { - Batch tmp{std::move(msg)}; + Batch tmp{msg}; return do_visit(tmp); } } diff --git a/src/endpoint.cc b/src/endpoint.cc index 06a5e65b..596b7a50 100644 --- a/src/endpoint.cc +++ b/src/endpoint.cc @@ -810,10 +810,10 @@ void endpoint::forward(std::vector ts) { caf::anon_send(native(core_), atom::subscribe_v, std::move(ts)); } -void endpoint::publish(topic t, data d) { +void endpoint::publish(topic t, const data& d) { BROKER_INFO("publishing" << d << "at" << t); caf::anon_send(native(core_), atom::publish_v, - make_data_message(std::move(t), std::move(d))); + make_data_message(std::move(t), d)); } void endpoint::publish(topic t, variant d) { @@ -827,10 +827,10 @@ void endpoint::publish(std::string_view t, const zeek::Message& d) { caf::anon_send(native(core_), atom::publish_v, make_data_message(t, d.raw())); } -void endpoint::publish(const endpoint_info& dst, topic t, data d) { +void endpoint::publish(const endpoint_info& dst, topic t, const data& d) { BROKER_INFO("publishing" << d << "at" << t << "to" << dst.node); caf::anon_send(native(core_), atom::publish_v, - make_data_message(std::move(t), std::move(d)), dst); + make_data_message(std::move(t), d), dst); } void endpoint::publish(const endpoint_info& dst, topic t, const variant& d) { diff --git a/src/publisher.cc b/src/publisher.cc index ef65889d..a9441053 100644 --- a/src/publisher.cc +++ b/src/publisher.cc @@ -226,7 +226,7 @@ void publisher::publish(const data& x) { dptr(queue_)->push(caf::make_span(&msg, 1)); } -void publisher::publish(std::vector xs) { +void publisher::publish(const std::vector& xs) { std::vector msgs; msgs.reserve(xs.size()); for (auto& x : xs)