You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2026/09/04 19:39:58 UTC
(trafficserver) branch master updated: clang-tidy: add low-churn checks (#13612)
This is an automated email from the ASF dual-hosted git repository.
bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new ca3eb0c450 clang-tidy: add low-churn checks (#13612)
ca3eb0c450 is described below
commit ca3eb0c4504feed722e744e2c7bb872fd38fea52
Author: Brian Neradt <br...@gmail.com>
AuthorDate: Fri Sep 4 14:39:51 2026 -0500
clang-tidy: add low-churn checks (#13612)
These checks catch avoidable copies, blocked moves, narrow loop
variables, and unclear ownership transfers. This patch fixes the current
findings and enables the checks in CI and editor configuration.
---
.clang-tidy | 4 ++++
.clang-tidy-ci | 4 ++++
plugins/multiplexer/dispatch.cc | 20 +++++++++++---------
plugins/multiplexer/dispatch.h | 5 +++--
src/iocore/net/ConnectionTracker.cc | 8 ++++----
src/iocore/net/SSLSecret.cc | 4 ++--
src/proxy/http/remap/NextHopHealthStatus.cc | 2 +-
src/proxy/http3/QPACK.cc | 6 +++---
8 files changed, 32 insertions(+), 21 deletions(-)
diff --git a/.clang-tidy b/.clang-tidy
index aff8a57e2b..6f00270e56 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -27,6 +27,7 @@ Checks: >-
bugprone-suspicious-realloc-usage,
bugprone-swapped-arguments,
bugprone-throw-keyword-missing,
+ bugprone-too-small-loop-variable,
bugprone-undelegated-constructor,
bugprone-unhandled-exception-at-new,
bugprone-unintended-char-ostream-output,
@@ -36,6 +37,7 @@ Checks: >-
google-readability-braces-around-statements,
google-readability-casting,
misc-redundant-expression,
+ misc-uniqueptr-reset-release,
modernize-deprecated-headers,
modernize-loop-convert,
modernize-raw-string-literal,
@@ -45,9 +47,11 @@ Checks: >-
modernize-use-override,
modernize-use-using,
performance-faster-string-find,
+ performance-for-range-copy,
performance-inefficient-algorithm,
performance-inefficient-vector-operation,
performance-move-constructor-init,
+ performance-no-automatic-move,
performance-unnecessary-copy-initialization,
performance-unnecessary-value-param,
portability-std-allocator-const
diff --git a/.clang-tidy-ci b/.clang-tidy-ci
index b1bceb2cc6..5a0f79e755 100644
--- a/.clang-tidy-ci
+++ b/.clang-tidy-ci
@@ -27,6 +27,7 @@ Checks: >-
bugprone-suspicious-realloc-usage,
bugprone-swapped-arguments,
bugprone-throw-keyword-missing,
+ bugprone-too-small-loop-variable,
bugprone-undelegated-constructor,
bugprone-unhandled-exception-at-new,
bugprone-unintended-char-ostream-output,
@@ -34,10 +35,13 @@ Checks: >-
bugprone-unused-raii,
bugprone-use-after-move,
misc-redundant-expression,
+ misc-uniqueptr-reset-release,
performance-faster-string-find,
+ performance-for-range-copy,
performance-inefficient-algorithm,
performance-inefficient-vector-operation,
performance-move-constructor-init,
+ performance-no-automatic-move,
performance-unnecessary-copy-initialization,
portability-std-allocator-const
WarningsAsErrors: '*'
diff --git a/plugins/multiplexer/dispatch.cc b/plugins/multiplexer/dispatch.cc
index 969b31575d..3a5c15129f 100644
--- a/plugins/multiplexer/dispatch.cc
+++ b/plugins/multiplexer/dispatch.cc
@@ -54,7 +54,7 @@ Request::Request(const std::string &h, const TSMBuffer b, const TSMLoc l) : host
assert(TSHttpHdrLengthGet(b, l) >= length);
}
-Request::Request(Request &&that) : host(std::move(that.host)), length(that.length), io(std::move(that.io))
+Request::Request(Request &&that) noexcept : host(std::move(that.host)), length(that.length), io(std::move(that.io))
{
assert(!host.empty());
assert(length > 0);
@@ -62,15 +62,17 @@ Request::Request(Request &&that) : host(std::move(that.host)), length(that.lengt
}
Request &
-Request::operator=(const Request &r)
+Request::operator=(Request &&r) noexcept
{
- host = r.host;
- length = r.length;
- io.reset(const_cast<Request &>(r).io.release());
- assert(!host.empty());
- assert(length > 0);
- assert(io.get() != nullptr);
- assert(r.io.get() == nullptr);
+ if (this != &r) {
+ host = std::move(r.host);
+ length = r.length;
+ io = std::move(r.io);
+ assert(!host.empty());
+ assert(length > 0);
+ assert(io.get() != nullptr);
+ assert(r.io.get() == nullptr);
+ }
return *this;
}
diff --git a/plugins/multiplexer/dispatch.h b/plugins/multiplexer/dispatch.h
index d8c4674aa6..e172264909 100644
--- a/plugins/multiplexer/dispatch.h
+++ b/plugins/multiplexer/dispatch.h
@@ -75,8 +75,9 @@ struct Request {
Request(const std::string &, const TSMBuffer, const TSMLoc);
Request(const Request &) = delete;
- Request(Request &&);
- Request &operator=(const Request &);
+ Request(Request &&) noexcept;
+ Request &operator=(const Request &) = delete;
+ Request &operator=(Request &&) noexcept;
};
using Requests = std::vector<Request>;
diff --git a/src/iocore/net/ConnectionTracker.cc b/src/iocore/net/ConnectionTracker.cc
index 8551961632..e8e56cabd1 100644
--- a/src/iocore/net/ConnectionTracker.cc
+++ b/src/iocore/net/ConnectionTracker.cc
@@ -229,7 +229,7 @@ Groups_To_JSON(std::vector<std::shared_ptr<ConnectionTracker::Group const>> cons
swoc::FixedBufferWriter null_bw{nullptr}; // Empty buffer for sizing work.
null_bw.print(header_fmt, groups.size()).extent();
- for (auto g : groups) {
+ for (auto const &g : groups) {
printer(null_bw, g.get());
}
extent = null_bw.extent() + trailer.size() - 2; // 2 for the trailing comma newline that will get clipped.
@@ -238,7 +238,7 @@ Groups_To_JSON(std::vector<std::shared_ptr<ConnectionTracker::Group const>> cons
swoc::FixedBufferWriter w(const_cast<char *>(text.data()), text.size());
w.restrict(trailer.size());
w.print(header_fmt, groups.size());
- for (auto g : groups) {
+ for (auto const &g : groups) {
printer(w, g.get());
}
w.restore(trailer.size());
@@ -670,7 +670,7 @@ ConnectionTracker::dump_outbound(FILE *f)
"Match");
fprintf(f, "------|-------|--------------------------|-----------------------------------|----------|\n");
- for (std::shared_ptr<Group const> g : groups) {
+ for (std::shared_ptr<Group const> const &g : groups) {
swoc::LocalBufferWriter<128> w;
w.print("{:7} | {:5} | {:24} | {:33} | {:8} |\n", g->_count.load(), g->_blocked.load(), g->_addr, g->_hash, g->_match_type);
fwrite(w.data(), w.size(), 1, f);
@@ -699,7 +699,7 @@ ConnectionTracker::dump_inbound(FILE *f)
"Match");
fprintf(f, "------|-------|--------------------------|-----------------------------------|----------|\n");
- for (std::shared_ptr<Group const> g : groups) {
+ for (std::shared_ptr<Group const> const &g : groups) {
swoc::LocalBufferWriter<128> w;
w.print("{:7} | {:5} | {:24} | {:33} | {:8} |\n", g->_count.load(), g->_blocked.load(), g->_addr, g->_hash, g->_match_type);
fwrite(w.data(), w.size(), 1, f);
diff --git a/src/iocore/net/SSLSecret.cc b/src/iocore/net/SSLSecret.cc
index 7249681aa2..5cf9aa6c99 100644
--- a/src/iocore/net/SSLSecret.cc
+++ b/src/iocore/net/SSLSecret.cc
@@ -88,8 +88,8 @@ std::string
SSLSecret::loadFile(const std::string &name)
{
Dbg(dbg_ctl_ssl_secret, "SSLSecret::loadFile(%s)", name.c_str());
- std::error_code error;
- std::string const data = swoc::file::load(swoc::file::path(name), error);
+ std::error_code error;
+ std::string data = swoc::file::load(swoc::file::path(name), error);
if (error) {
Dbg(dbg_ctl_ssl_secret_err, "SSLSecret::loadFile(%s) failed error code=%d message=%s", name.c_str(), error.value(),
error.message().c_str());
diff --git a/src/proxy/http/remap/NextHopHealthStatus.cc b/src/proxy/http/remap/NextHopHealthStatus.cc
index 35e42aa611..1379a2e5d6 100644
--- a/src/proxy/http/remap/NextHopHealthStatus.cc
+++ b/src/proxy/http/remap/NextHopHealthStatus.cc
@@ -30,7 +30,7 @@
void
NextHopHealthStatus::insert(std::vector<std::shared_ptr<HostRecord>> &hosts)
{
- for (auto h : hosts) {
+ for (auto const &h : hosts) {
for (auto protocol = h->protocols.begin(); protocol != h->protocols.end(); ++protocol) {
const std::string host_port = h->getHostPort((*protocol)->port);
host_map.emplace(std::make_pair(host_port, h));
diff --git a/src/proxy/http3/QPACK.cc b/src/proxy/http3/QPACK.cc
index 38aa3a5630..d318690228 100644
--- a/src/proxy/http3/QPACK.cc
+++ b/src/proxy/http3/QPACK.cc
@@ -1233,9 +1233,9 @@ const XpackLookupResult
QPACK::StaticTable::lookup(const char *name, size_t name_len, const char *value, size_t value_len)
{
XpackLookupResult::MatchType match_type = XpackLookupResult::MatchType::NONE;
- uint16_t i = 0;
- uint16_t candidate_index = 0;
- int n = countof(STATIC_HEADER_FIELDS);
+ uint32_t i = 0;
+ uint32_t candidate_index = 0;
+ unsigned int n = countof(STATIC_HEADER_FIELDS);
for (; i < n; ++i) {
const Header &h = STATIC_HEADER_FIELDS[i];