mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2026-11-25 13:11:36 +00:00
feat(tidy): add fairmq-performance-channel-lookup-in-loop
- Report GetChannel() and GetChannels() calls in an override of ConditionalRun() or in a loop in an override of Run(). Each call looks up the channel name in a map. - Skip the short form Send(msg, "name"): it is the usual style. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
38
test/tidy/fairmq-performance-channel-lookup-in-loop.cxx
Normal file
38
test/tidy/fairmq-performance-channel-lookup-in-loop.cxx
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <fairmq/Device.h>
|
||||
|
||||
struct Sampler : fair::mq::Device
|
||||
{
|
||||
bool ConditionalRun() override
|
||||
{
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:20: warning: 'GetChannel()' looks up the channel by name in each iteration of 'ConditionalRun()'; look it up once, e.g. in 'InitTask()', and keep a reference [fairmq-performance-channel-lookup-in-loop]
|
||||
auto& ch = GetChannel("data");
|
||||
auto msg(ch.NewMessage());
|
||||
return ch.Send(msg) >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
struct Looper : fair::mq::Device
|
||||
{
|
||||
void Run() override
|
||||
{
|
||||
auto& out = GetChannel("data");
|
||||
while (!NewStatePending()) {
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:24: warning: 'GetChannel()' looks up the channel by name in each iteration of a loop in 'Run()'; look it up once, e.g. in 'InitTask()', and keep a reference [fairmq-performance-channel-lookup-in-loop]
|
||||
auto& in = GetChannel("in", 0);
|
||||
auto msg(in.NewMessage());
|
||||
// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: 'GetChannels()' looks up the channel by name in each iteration of a loop in 'Run()'; look it up once, e.g. in 'InitTask()', and keep a reference [fairmq-performance-channel-lookup-in-loop]
|
||||
if (GetChannels().count("monitor") == 0) {
|
||||
out.Send(msg);
|
||||
}
|
||||
}
|
||||
// Not reported: once per loop, or in a lambda.
|
||||
for (auto& sub : GetChannels().at("data")) {
|
||||
static_cast<void>(sub);
|
||||
}
|
||||
for (auto& ch = GetChannel("data"); !NewStatePending();) {
|
||||
auto msg(ch.NewMessage());
|
||||
auto send = [&] { return GetChannel("data").Send(msg); };
|
||||
send();
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user