Fix clang-tidy performance-inefficient-string-concatenation warnings

This commit is contained in:
Tim Wojtulewicz 2025-04-25 16:57:22 -07:00
parent cb8c35748a
commit c609d5c90a
7 changed files with 15 additions and 9 deletions

View file

@ -7,6 +7,7 @@ Checks: [-*,
performance-inefficient-vector-operation, performance-inefficient-vector-operation,
performance-move-const-argument, performance-move-const-argument,
performance-unnecessary-copy-initialization, performance-unnecessary-copy-initialization,
performance-inefficient-string-concatenation,
# Skipping these temporarily because they are very noisy # Skipping these temporarily because they are very noisy
-bugprone-narrowing-conversions, -bugprone-narrowing-conversions,

View file

@ -467,7 +467,7 @@ static std::optional<FuncType::Prototype> func_type_check(const FuncType* decl,
auto msg = ad->DeprecationMessage(); auto msg = ad->DeprecationMessage();
if ( ! msg.empty() ) if ( ! msg.empty() )
msg = ": " + msg; msg = std::string{": "}.append(msg);
reporter->Deprecation(util::fmt("use of deprecated parameter '%s'%s (%s)", rval->args->FieldName(i), reporter->Deprecation(util::fmt("use of deprecated parameter '%s'%s (%s)", rval->args->FieldName(i),
msg.data(), obj_desc_short(impl).c_str()), msg.data(), obj_desc_short(impl).c_str()),

View file

@ -357,8 +357,10 @@ void IRC_Analyzer::DeliverStream(int length, const u_char* line, bool orig) {
parts.erase(parts.begin(), parts.begin() + 4); parts.erase(parts.begin(), parts.begin() + 4);
string real_name = parts[0]; string real_name = parts[0];
for ( size_t i = 1; i < parts.size(); ++i ) for ( size_t i = 1; i < parts.size(); ++i ) {
real_name = real_name + " " + parts[i]; real_name += " ";
real_name += parts[i];
}
if ( real_name[0] == ':' ) if ( real_name[0] == ':' )
real_name = real_name.substr(1); real_name = real_name.substr(1);

View file

@ -768,7 +768,7 @@ bool Manager::TraverseRecord(Stream* stream, Filter* filter, RecordType* rt, Tab
// Add the ext prefix if this is an ext field. // Add the ext prefix if this is an ext field.
if ( j < num_ext_fields ) if ( j < num_ext_fields )
new_path = filter->ext_prefix + new_path; new_path = string{filter->ext_prefix}.append(new_path);
if ( t->InternalType() == TYPE_INTERNAL_OTHER ) { if ( t->InternalType() == TYPE_INTERNAL_OTHER ) {
if ( t->Tag() == TYPE_RECORD ) { if ( t->Tag() == TYPE_RECORD ) {

View file

@ -341,9 +341,12 @@ void CPPCompile::RegisterCompiledBody(const string& f) {
auto be = body_events.find(f); auto be = body_events.find(f);
if ( be != body_events.end() ) if ( be != body_events.end() )
for ( const auto& e : be->second ) { for ( const auto& e : be->second ) {
if ( events.size() > 0 ) if ( ! events.empty() )
events += ", "; events += ", ";
events = events + "\"" + e + "\"";
events += "\"";
events += e;
events += "\"";
} }
events = string("{") + events + "}"; events = string("{") + events + "}";

View file

@ -28,7 +28,7 @@ string CPPCompile::GenListExpr(const Expr* e, GenType gt, bool nested) {
if ( nested && e_i->Tag() == EXPR_LIST ) if ( nested && e_i->Tag() == EXPR_LIST )
// These are table or set indices. // These are table or set indices.
gen_i = string("index_val__CPP({") + gen_i + "})"; gen_i = util::fmt("index_val__CPP({%s})", gen_i.c_str());
gen += gen_i; gen += gen_i;
@ -1196,7 +1196,7 @@ string CPPCompile::GenLambdaClone(const LambdaExpr* l, bool all_deep) {
if ( captures && ! IsNativeType(id_t) ) { if ( captures && ! IsNativeType(id_t) ) {
for ( const auto& c : *captures ) for ( const auto& c : *captures )
if ( id == c.Id() && (c.IsDeepCopy() || all_deep) ) if ( id == c.Id() && (c.IsDeepCopy() || all_deep) )
arg = string("cast_intrusive<") + TypeName(id_t) + ">(" + arg + "->Clone())"; arg = util::fmt("cast_intrusive<%s>(%s->Clone())", TypeName(id_t), arg.c_str());
} }
cl_args += ", " + arg; cl_args += ", " + arg;

View file

@ -299,7 +299,7 @@ void CPPCompile::GenStandaloneActivation() {
hashes += Fmt(h); hashes += Fmt(h);
} }
hashes = "{" + hashes + "}"; hashes = std::string{"{"}.append(hashes).append("}");
auto f = fb.first; auto f = fb.first;
const auto& fn = f->GetName(); const auto& fn = f->GetName();