Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/neverlord/clang-tidy'
Browse files Browse the repository at this point in the history
* origin/topic/neverlord/clang-tidy:
  Fix/suppress clang-tidy findings
  • Loading branch information
awelzel committed Jun 24, 2024
2 parents 3dc3aef + 58e270b commit d0f9016
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 31 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -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*,
Expand Down
12 changes: 7 additions & 5 deletions bindings/python/_broker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<topic_data_pair> batch) {
for (auto& item : batch)
Expand Down
10 changes: 5 additions & 5 deletions libbroker/broker/endpoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,10 @@ void endpoint::forward(std::vector<topic> 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) {
Expand All @@ -827,16 +827,16 @@ 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) {
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, std::string_view t,
Expand Down
4 changes: 2 additions & 2 deletions libbroker/broker/endpoint.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion libbroker/broker/publisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void publisher::publish(const data& x) {
dptr(queue_)->push(caf::make_span(&msg, 1));
}

void publisher::publish(std::vector<data> xs) {
void publisher::publish(const std::vector<data>& xs) {
std::vector<data_message> msgs;
msgs.reserve(xs.size());
for (auto& x : xs)
Expand Down
2 changes: 1 addition & 1 deletion libbroker/broker/publisher.hh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public:
void publish(const data& x);

/// Sends `xs` to all subscribers.
void publish(std::vector<data> xs);
void publish(const std::vector<data>& xs);

/// Sends `x` to all subscribers.
void publish(set_builder&& x);
Expand Down
8 changes: 8 additions & 0 deletions libbroker/broker/topic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T,
Expand Down
2 changes: 2 additions & 0 deletions libbroker/broker/variant_list.hh
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public:

variant_list() noexcept = default;

variant_list(variant_list&&) noexcept = default;

variant_list(const variant_list&) noexcept = default;

bool empty() const noexcept {
Expand Down
8 changes: 4 additions & 4 deletions libbroker/broker/variant_table.hh
Original file line number Diff line number Diff line change
Expand Up @@ -133,23 +133,23 @@ public:

// -- key lookup -------------------------------------------------------------

iterator find(const variant& key) const noexcept {
iterator find(const variant& key) const {
return iterator{values_->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 <class T>
variant do_lookup(T key) const noexcept {
variant do_lookup(T key) const {
if (values_ == nullptr)
return variant{};
auto key_view = variant_data{key};
Expand Down
28 changes: 15 additions & 13 deletions libbroker/broker/zeek.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {}
};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -570,7 +572,7 @@ private:
};

template <class F>
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);
Expand All @@ -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);
}
}
Expand Down

0 comments on commit d0f9016

Please sign in to comment.