Skip to content

Commit

Permalink
clang-tidy: pass function by ref
Browse files Browse the repository at this point in the history
Found with performance-unnecessary-value-param
Found with performance-unnecessary-copy-initialization

Signed-off-by: Rosen Penev <rosenp@gmail.com>
  • Loading branch information
neheb committed Jan 9, 2024
1 parent 17904ed commit 224085c
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 40 deletions.
6 changes: 3 additions & 3 deletions modules/lmdbbackend/lmdbbackend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ std::shared_ptr<LMDBBackend::RecordsRWTransaction> LMDBBackend::getRecordsRWTran
return ret;
}

std::shared_ptr<LMDBBackend::RecordsROTransaction> LMDBBackend::getRecordsROTransaction(uint32_t id, std::shared_ptr<LMDBBackend::RecordsRWTransaction> rwtxn)
std::shared_ptr<LMDBBackend::RecordsROTransaction> LMDBBackend::getRecordsROTransaction(uint32_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn)
{
auto& shard = d_trecords[id % s_shards];
if (!shard.env) {
Expand Down Expand Up @@ -1627,7 +1627,7 @@ bool LMDBBackend::getDomainInfo(const DNSName& domain, DomainInfo& di, bool gets
return true;
}

int LMDBBackend::genChangeDomain(const DNSName& domain, std::function<void(DomainInfo&)> func)
int LMDBBackend::genChangeDomain(const DNSName& domain, const std::function<void(DomainInfo&)>& func)
{
auto txn = d_tdomains->getRWTransaction();

Expand All @@ -1641,7 +1641,7 @@ int LMDBBackend::genChangeDomain(const DNSName& domain, std::function<void(Domai
return true;
}

int LMDBBackend::genChangeDomain(uint32_t id, std::function<void(DomainInfo&)> func)
int LMDBBackend::genChangeDomain(uint32_t id, const std::function<void(DomainInfo&)>& func)
{
DomainInfo di;

Expand Down
6 changes: 3 additions & 3 deletions modules/lmdbbackend/lmdbbackend.hh
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,9 @@ private:
shared_ptr<RecordsROTransaction> d_rotxn; // for lookup and list
shared_ptr<RecordsRWTransaction> d_rwtxn; // for feedrecord within begin/aborttransaction
std::shared_ptr<RecordsRWTransaction> getRecordsRWTransaction(uint32_t id);
std::shared_ptr<RecordsROTransaction> getRecordsROTransaction(uint32_t id, std::shared_ptr<LMDBBackend::RecordsRWTransaction> rwtxn = nullptr);
int genChangeDomain(const DNSName& domain, std::function<void(DomainInfo&)> func);
int genChangeDomain(uint32_t id, std::function<void(DomainInfo&)> func);
std::shared_ptr<RecordsROTransaction> getRecordsROTransaction(uint32_t id, const std::shared_ptr<LMDBBackend::RecordsRWTransaction>& rwtxn = nullptr);
int genChangeDomain(const DNSName& domain, const std::function<void(DomainInfo&)>& func);
int genChangeDomain(uint32_t id, const std::function<void(DomainInfo&)>& func);
void deleteDomainRecords(RecordsRWTransaction& txn, uint32_t domain_id, uint16_t qtype = QType::ANY);

void getAllDomainsFiltered(vector<DomainInfo>* domains, const std::function<bool(DomainInfo&)>& allow);
Expand Down
2 changes: 1 addition & 1 deletion pdns/dnswasher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class IPCipherObfuscator : public IPObfuscator
}
}

static std::unique_ptr<IPObfuscator> make(std::string key, bool decrypt)
static std::unique_ptr<IPObfuscator> make(const std::string& key, bool decrypt)
{
return std::make_unique<IPCipherObfuscator>(key, decrypt);
}
Expand Down
3 changes: 2 additions & 1 deletion pdns/iputils.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,8 @@ public:
d_addr.sin4.sin_port = 0; // this guarantees d_network compares identical
}

AddressAndPortRange(ComboAddress ca, uint8_t addrMask, uint8_t portMask = 0): d_addr(std::move(ca)), d_addrMask(addrMask), d_portMask(portMask)
AddressAndPortRange(ComboAddress ca, uint8_t addrMask, uint8_t portMask = 0) :
d_addr(ca), d_addrMask(addrMask), d_portMask(portMask)
{
if (!d_addr.isIPv4()) {
d_portMask = 0;
Expand Down
39 changes: 21 additions & 18 deletions pdns/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ using json11::Json;

static inline int intFromJsonInternal(const Json& container, const std::string& key, const bool have_default, const int default_value)
{
auto val = container[key];
const auto& val = container[key];
if (val.is_number()) {
return val.int_value();
} else if (val.is_string()) {
}

if (val.is_string()) {
try {
return std::stoi(val.string_value());
} catch (std::out_of_range&) {
throw JsonException("Key '" + string(key) + "' is out of range");
}
} else {
if (have_default) {
return default_value;
}
throw JsonException("Key '" + string(key) + "' not an Integer or not present");
}

if (have_default) {
return default_value;
}
throw JsonException("Key '" + string(key) + "' not an Integer or not present");
}

int intFromJson(const Json& container, const std::string& key)
Expand Down Expand Up @@ -78,21 +80,23 @@ unsigned int uintFromJson(const Json& container, const std::string& key, const u

static inline double doubleFromJsonInternal(const Json& container, const std::string& key, const bool have_default, const double default_value)
{
auto val = container[key];
const auto& val = container[key];
if (val.is_number()) {
return val.number_value();
} else if (val.is_string()) {
}

if (val.is_string()) {
try {
return std::stod(val.string_value());
} catch (std::out_of_range&) {
throw JsonException("Value for key '" + string(key) + "' is out of range");
}
} else {
if (have_default) {
return default_value;
}
throw JsonException("Key '" + string(key) + "' not an Integer or not present");
}

if (have_default) {
return default_value;
}
throw JsonException("Key '" + string(key) + "' not an Integer or not present");
}

double doubleFromJson(const Json& container, const std::string& key)
Expand All @@ -107,17 +111,16 @@ double doubleFromJson(const Json& container, const std::string& key, const doubl

string stringFromJson(const Json& container, const std::string &key)
{
const Json val = container[key];
const auto& val = container[key];
if (val.is_string()) {
return val.string_value();
} else {
throw JsonException("Key '" + string(key) + "' not present or not a String");
}
throw JsonException("Key '" + string(key) + "' not present or not a String");
}

static inline bool boolFromJsonInternal(const Json& container, const std::string& key, const bool have_default, const bool default_value)
{
auto val = container[key];
const auto& val = container[key];
if (val.is_bool()) {
return val.bool_value();
}
Expand Down
5 changes: 3 additions & 2 deletions pdns/lua-record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ typedef struct AuthLuaRecordContext

static thread_local unique_ptr<lua_record_ctx_t> s_lua_record_ctx;

static vector<string> genericIfUp(const boost::variant<iplist_t, ipunitlist_t>& ips, boost::optional<opts_t> options, std::function<bool(const ComboAddress&, const opts_t&)> upcheckf, uint16_t port = 0) {
static vector<string> genericIfUp(const boost::variant<iplist_t, ipunitlist_t>& ips, boost::optional<opts_t> options, const std::function<bool(const ComboAddress&, const opts_t&)>& upcheckf, uint16_t port = 0)
{
vector<vector<ComboAddress> > candidates;
opts_t opts;
if(options)
Expand Down Expand Up @@ -894,7 +895,7 @@ static void setupLuaRecords(LuaContext& lua)
auto checker = [](const ComboAddress& addr, const opts_t& opts) {
return g_up.isUp(addr, opts);
};
return genericIfUp(ips, std::move(options), checker, port);
return genericIfUp(ips, options, checker, port);
});

lua.writeFunction("ifurlextup", [](const vector<pair<int, opts_t> >& ipurls, boost::optional<opts_t> options) {
Expand Down
8 changes: 3 additions & 5 deletions pdns/statnode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ StatNode::Stat StatNode::print(unsigned int depth, Stat newstat, bool silent) co
return newstat;
}


void StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) const
void StatNode::visit(const visitor_t& visitor, Stat& newstat, unsigned int depth) const
{
Stat childstat(s);

Expand All @@ -49,8 +48,7 @@ void StatNode::visit(visitor_t visitor, Stat &newstat, unsigned int depth) const
newstat += childstat;
}


void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, boost::optional<const ComboAddress&> remote)
void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, const boost::optional<const ComboAddress&>& remote)
{
// cerr<<"FIRST submit called on '"<<domain<<"'"<<endl;
std::vector<string> tmp = domain.getRawLabels();
Expand All @@ -69,7 +67,7 @@ void StatNode::submit(const DNSName& domain, int rcode, unsigned int bytes, bool
www.powerdns.com.
*/

void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, boost::optional<const ComboAddress&> remote, unsigned int count, bool hit)
void StatNode::submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, const boost::optional<const ComboAddress&>& remote, unsigned int count, bool hit)
{
// cerr<<"Submit called for domain='"<<domain<<"': ";
// for(const std::string& n : labels)
Expand Down
6 changes: 3 additions & 3 deletions pdns/statnode.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ public:
std::string fullname;
uint8_t labelsCount{0};

void submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, boost::optional<const ComboAddress&> remote);
void submit(const DNSName& domain, int rcode, unsigned int bytes, bool hit, const boost::optional<const ComboAddress&>& remote);
Stat print(unsigned int depth=0, Stat newstat=Stat(), bool silent=false) const;
void visit(visitor_t visitor, Stat& newstat, unsigned int depth=0) const;
void visit(const visitor_t& visitor, Stat& newstat, unsigned int depth = 0) const;
bool empty() const
{
return children.empty() && s.remotes.empty();
}
children_t children;

private:
void submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, boost::optional<const ComboAddress&> remote, unsigned int count, bool hit);
void submit(std::vector<string>::const_iterator end, std::vector<string>::const_iterator begin, const std::string& domain, int rcode, unsigned int bytes, const boost::optional<const ComboAddress&>& remote, unsigned int count, bool hit);
};
7 changes: 4 additions & 3 deletions pdns/tcpiohandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,16 @@ protected:
class TCPIOHandler
{
public:

TCPIOHandler(const std::string& host, bool hostIsAddr, int socket, const struct timeval& timeout, std::shared_ptr<TLSCtx> ctx): d_socket(socket)
TCPIOHandler(const std::string& host, bool hostIsAddr, int socket, const struct timeval& timeout, const std::shared_ptr<TLSCtx>& ctx) :
d_socket(socket)
{
if (ctx) {
d_conn = ctx->getClientConnection(host, hostIsAddr, d_socket, timeout);
}
}

TCPIOHandler(int socket, const struct timeval& timeout, std::shared_ptr<TLSCtx> ctx, time_t now): d_socket(socket)
TCPIOHandler(int socket, const struct timeval& timeout, const std::shared_ptr<TLSCtx>& ctx, time_t now) :
d_socket(socket)
{
if (ctx) {
d_conn = ctx->getConnection(d_socket, timeout, now);
Expand Down
3 changes: 2 additions & 1 deletion pdns/webserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ void WebServer::registerWebHandler(const string& url, const HandlerFunction& han
registerBareHandler(url, f, method);
}

static void *WebServerConnectionThreadStart(const WebServer* webServer, std::shared_ptr<Socket> client) {
static void* WebServerConnectionThreadStart(const WebServer* webServer, const std::shared_ptr<Socket>& client)
{
setThreadName("rec/webhndlr");
const std::string msg = "Exception while serving a connection in main webserver thread";
try {
Expand Down

0 comments on commit 224085c

Please sign in to comment.