diff --git a/.clang-tidy-baseline.txt b/.clang-tidy-baseline.txt index 5f27d3026..8c48d496e 100644 --- a/.clang-tidy-baseline.txt +++ b/.clang-tidy-baseline.txt @@ -9,7 +9,7 @@ # Locally: python3 scripts/tidyadvisory_diff.py --report --baseline .clang-tidy-baseline.txt # --normalized-out (python3 scripts/tidyadvisory_diff.py --selftest checks the parser) # generated from: the advisory clang-tidy 22 report of CI job 127414521171 (PR 537 head 51695de4a; content now on main e5498e79f), deduplicated across translation units -# rows: 967 +# rows: 971 src/abicheck.h bugprone-easily-swappable-parameters inline std::string modelKey( std::string_view sha, std::string_view path ) src/arch.h bugprone-easily-swappable-parameters inline PathRuleMatch pathRuleMatches( const PathRule& pr, std::string_view src, std::string_view dst ) src/arch.h bugprone-easily-swappable-parameters inline bool archViolates( const ArchRules& r, int la, int lb ) @@ -100,7 +100,6 @@ src/defattrib.h bugprone-unchecked-optional-access untied[grp] = editCheckTieDec src/defattrib.h performance-inefficient-vector-operation for( std::size_t i = 0; i < rollup.shown; ++i ) src/defectshape.h bugprone-branch-clone { src/defectshape.h bugprone-branch-clone { -src/defectshape.h bugprone-branch-clone { src/defectshape.h bugprone-easily-swappable-parameters inline Tok lexPythonString( std::string_view s, std::uint32_t b, std::size_t q ) src/defectshape.h bugprone-easily-swappable-parameters inline bool callHoldsDirective( const std::vector& directives, std::uint32_t open, std::uint32_t close ) noexcept src/defectshape.h bugprone-easily-swappable-parameters inline bool hasUtf8Guard( std::string_view src, const std::vector& toks, std::size_t from, std::size_t to ) noexcept @@ -111,7 +110,6 @@ src/defectshape.h bugprone-easily-swappable-parameters inline std::size_t ellips src/defectshape.h bugprone-easily-swappable-parameters inline std::size_t skipQuoted( std::string_view s, std::size_t i, char q ) noexcept src/defectshape.h bugprone-easily-swappable-parameters inline std::string joinTokens( std::string_view src, const std::vector& toks, std::size_t from, std::size_t to ) src/defectshape.h bugprone-easily-swappable-parameters inline void scanDedupFirstFunction( std::string_view src, const std::vector& toks, std::size_t from, std::size_t to, std::vector& out ) -src/defectshape.h performance-faster-string-find else if( w.rfind( "<<<", 0 ) == 0 || w.rfind( "2>", 0 ) == 0 || w.rfind( ">", 0 ) == 0 ) src/defslookup.h bugprone-easily-swappable-parameters inline PathAlts pathAltsOf( const IngestResult& ing, const Graph& g, std::string_view srcN, std::string_view dstN, bool srcGlob, bool dstGlob, src/defslookup.h performance-inefficient-string-concatenation r.sel = file + ":" + owned; src/defslookup.h performance-inefficient-string-concatenation tries.push_back( file + ":" + owned ); @@ -293,6 +291,7 @@ src/graph.h bugprone-narrowing-conversions t.localNameSet[ key ] |= localNameEvi src/graph.h bugprone-return-const-ref-from-parameter return pairs > 0 ? adj : full; src/graph.h bugprone-switch-missing-default-case switch( prov ) src/graph.h bugprone-unchecked-optional-access && openedPaths.find( std::string( rubyTypedWritten( *typed ) ) ) == openedPaths.end(); +src/graph.h bugprone-unchecked-optional-access const std::string_view head = *head_; src/graph.h clang-analyzer-deadcode.DeadStores case FalseEdgeRules::Verdict::External: disposition = vetoExternal( r ); continue; src/graph.h clang-analyzer-deadcode.DeadStores case FalseEdgeRules::Verdict::Local: ++g.unresolvedOut[ r.fromSymbol ]; disposition = CallDisposition::Unresolved; continue; src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::Bound; @@ -306,6 +305,7 @@ src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::De src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::Declined; src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::Declined; src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::Declined; +src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::Declined; src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::FileScope; // no caller node for an edge; the use-site index still lists the site src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::OtherRoot; src/graph.h clang-analyzer-deadcode.DeadStores disposition = CallDisposition::OtherRoot; @@ -334,6 +334,7 @@ src/graph.h clang-analyzer-deadcode.DeadStores disposition = vetoExternal( r ); src/graph.h clang-analyzer-deadcode.DeadStores disposition = vetoExternal( r ); src/graph.h clang-analyzer-deadcode.DeadStores disposition = vetoExternal( r ); src/graph.h clang-analyzer-deadcode.DeadStores disposition = vetoExternal( r ); +src/graph.h clang-analyzer-deadcode.DeadStores disposition = vetoExternal( r ); src/graph.h clang-analyzer-deadcode.DeadStores disposition = vetoExternal( r ); // RSpec's own target, a class whose lookup leaves the tree: the method Ruby runs is outside it src/graph.h clang-analyzer-deadcode.DeadStores disposition = vetoExternal( r ); // every namesake is out of reach: the method Ruby runs is outside the tree src/graph.h clang-analyzer-deadcode.DeadStores disposition = vetoExternal( r ); // every target is one this call cannot reach: not a decline of any of them @@ -536,7 +537,6 @@ src/ingest_valuerefs.h performance-inefficient-string-concatenation chain = std: src/ingest_valuerefs.h performance-inefficient-string-concatenation climbed = std::string( up ) + "." + climbed; src/ingest_valuerefs.h performance-inefficient-string-concatenation s.into = fn + "#" + param; src/ingest_valuerefs.h performance-inefficient-string-concatenation tail = tail.empty() ? std::string( text( fld ) ) : std::string( text( fld ) ) + "." + tail; -src/ingest_valuerefs.h performance-move-const-arg r.memberCtor = slotCtor( std::move( key ), kw ); src/ingest_valuerefs.h performance-unnecessary-value-param bool paramDefault( std::string param, Slot& s ) const src/ingest_valuerefs.h performance-unnecessary-value-param void emitSlotCall( TSNode call, TSNode f, TSNode root, std::string& chain, std::string key, bool kw ) src/jsrunner.h bugprone-easily-swappable-parameters inline ModuleScan scanModule( std::string_view source, std::string_view path ) @@ -557,7 +557,7 @@ src/layout.h bugprone-easily-swappable-parameters inline std::size_t matchBracke src/layout.h bugprone-easily-swappable-parameters inline void addConst( ConstTable& table, std::string_view name, std::string_view value ) src/layout.h bugprone-easily-swappable-parameters std::int64_t apply( char op, std::int64_t a, std::int64_t b ) src/legenddict.h bugprone-easily-swappable-parameters const auto row = [ & ]( std::string_view attr, std::string_view element, std::string_view source ) -src/legenddict.h bugprone-suspicious-missing-comma ": the answer's rows come first; its root keeps only task= changed= from= to=, and " +src/legenddict.h bugprone-suspicious-missing-comma ": this LAST child is only the legend pointer; the root keeps every attribute it " src/lexical.h bugprone-easily-swappable-parameters const std::vector* symbolScoreMul, int pathFieldDefaultW = 0, src/lexical.h bugprone-easily-swappable-parameters inline std::vector lexicalScoresTiered( const IngestResult& ing, const std::vector& outOff, src/lexical.h bugprone-incorrect-roundings cut.dropPct = ( bestDrop >= kMinCliffDrop ) ? int( bestDrop * 100.0 + 0.5 ) : 0; @@ -567,13 +567,13 @@ src/lintrules.h bugprone-easily-swappable-parameters inline void appendFileConst src/lintrules.h performance-inefficient-vector-operation for( const ErrorMaskRule& rule : kErrorMaskRules ) src/listedin.h bugprone-easily-swappable-parameters inline bool inNestedPackage( const IngestResult& ing, std::uint32_t fileId, std::string_view rel, std::string_view mdir ) src/lsp.h bugprone-branch-clone case rw::SymKind::NamedType: return 5; // Class — LSP has no defined-type/alias kind; gopls files a non-struct named type here too -src/lsp.h bugprone-branch-clone { src/lsp.h bugprone-easily-swappable-parameters inline bool lspFindFile( const rw::IngestResult& ing, const std::string& cwd, src/lsp.h bugprone-easily-swappable-parameters inline bool lspIdentSpan( const LspDoc& d, std::size_t byte, std::size_t& b0, std::size_t& b1 ) src/lsp.h bugprone-easily-swappable-parameters inline bool lspLineCol( const LspDoc& d, std::size_t byte, std::uint32_t& line, std::uint32_t& ch ) src/lsp.h bugprone-easily-swappable-parameters inline std::string lspLocationJson( const rw::IngestResult& ing, const std::string& cwd, std::uint32_t fileId, src/lsp.h bugprone-implicit-widening-of-multiplication-result inline constexpr std::size_t kLspMaxBodyBytes = 32u * 1024u * 1024u; src/lsp.h bugprone-implicit-widening-of-multiplication-result inline constexpr std::size_t kLspMaxHeaderBytes = 64u * 1024u; +src/lsp.h bugprone-throwing-static-initialization rw::lspmap::LangMap gLangMap; src/main.cpp bugprone-easily-swappable-parameters NoteTargetResolution noteTargetForDefinition( const MainDispatch& d, rw::NodeId def, const std::string& rawTarget, src/main.cpp bugprone-easily-swappable-parameters inline UnservedDefs unservedDefsOf( const rw::IngestResult& ing, const std::vector& requested, std::vector served, src/main.cpp bugprone-easily-swappable-parameters std::size_t fullEstTokens, std::size_t tokenBudget, const rw::Config& cfg ) @@ -644,6 +644,8 @@ src/mergescout.h bugprone-easily-swappable-parameters inline Arm computeWorkingT src/mergescout.h bugprone-easily-swappable-parameters inline PairOverlap computeOnePairOverlap( std::size_t a, std::size_t b, const Arm& armA, const Arm& armB ) src/model.h bugprone-easily-swappable-parameters inline bool isJsTsBuiltinMember( std::string_view ctor, std::string_view name ) noexcept src/model.h bugprone-easily-swappable-parameters inline std::string_view relForHash( std::string_view path, std::string_view root ) noexcept +src/model.h bugprone-incorrect-roundings return std::uint32_t( tangleT( in ) * 10.0 + 0.5 ); +src/model.h bugprone-incorrect-roundings return std::uint32_t( tangleT( in ) * std::log2( double( in.loc ) / double( kTangleAmpLoc ) ) * 10.0 + 0.5 ); src/model.h bugprone-throwing-static-initialization RIPWIRE_LAYOUT_REGISTER_TYPES( RIPWIRE_LAYOUT_TYPE_ENTRY( std::string ), src/model.h clang-analyzer-optin.performance.Padding struct VrSlotLang src/naminglens.h bugprone-branch-clone { @@ -851,6 +853,7 @@ src/serialize.h bugprone-incorrect-roundings return std::size_t( double( emitted src/serialize.h bugprone-incorrect-roundings return std::size_t( tokensF + 0.5 ); src/serialize.h bugprone-narrowing-conversions const std::vector nodes( order.begin(), order.begin() + keep ); // rank order, id 0..keep-1 index src/serialize.h clang-analyzer-unix.Stream while( ( n = std::fread( buf, 1, sizeof( buf ), in ) ) > 0 ) +src/shstatus.h bugprone-unchecked-optional-access const detail::Walker& w2 = *last; src/situ.h bugprone-easily-swappable-parameters inline bool hunkFullyInBodies( const std::vector>& spans, std::uint32_t hStart, src/situ.h bugprone-easily-swappable-parameters inline std::string fileListRefusalText( const IngestResult& ing, std::string_view lead, std::string_view selector, src/situ.h bugprone-easily-swappable-parameters std::string_view nextInvocation = {}, std::string_view extraAttrs = {} ) @@ -899,10 +902,10 @@ src/taskroute.h bugprone-easily-swappable-parameters std::string command, int sc src/taskroute.h clang-analyzer-deadcode.DeadStores hasUpper = true; src/testmap.h bugprone-easily-swappable-parameters const std::vector* skipSym, std::span partnerOf, src/testmap.h bugprone-easily-swappable-parameters inline bool isTestPartnerOf( std::string_view testPath, std::string_view srcPath ) noexcept -src/testmap.h bugprone-exception-escape const auto groupable = [ & ]( std::uint32_t i ) noexcept src/testmap.h bugprone-narrowing-conversions jsRow[ ing.symbols[ site.caller ].fileId ] |= char( langFacts( ing.symbols[ site.caller ].lang ).importBoundConstruction ); src/testmap.h bugprone-narrowing-conversions void note( const Reference& r ) { mixed[ r.fileId ] |= char( written( r ) != first[ r.fileId ] ); } src/testmap.h performance-unnecessary-value-param inline JoinedTestRows testRowsList( const TestRunnerIndex& idx, std::span rows, const TestRowShape& shape, EscapeFn esc, std::string_view sep = {} ) +src/testmap.h performance-unnecessary-value-param inline std::string groupRunTail( RowDialect dialect, std::string_view head, EscapeFn esc ) src/testmap.h performance-unnecessary-value-param inline std::string renderSingleTestRow( const TestRunnerIndex& idx, const TestRowOut& r, const TestRowShape& shape, EscapeFn esc ) src/testmap.h performance-unnecessary-value-param inline std::string renderTestRowGroup( std::span rows, std::span members, const TestRowShape& shape, EscapeFn esc ) src/testmap.h performance-unnecessary-value-param inline std::vector testRowsRendered( const TestRunnerIndex& idx, std::span rows, const TestRowShape& shape, EscapeFn esc, @@ -935,6 +938,7 @@ src/verbs_for.h bugprone-easily-swappable-parameters inline std::string forLensJ src/verbs_for.h bugprone-easily-swappable-parameters inline std::string renderForFileTailXml( const rw::FileTail& tail, std::size_t tokenBudget, src/verbs_for.h bugprone-easily-swappable-parameters rw::RedactCounts* redactPtr, std::size_t committedBytes, std::size_t bundleBudget, src/verbs_for.h bugprone-incorrect-roundings const std::size_t nextTokens = std::size_t( double( withKey ) / kBytesPerTokenDefault + 0.5 ); +src/verbs_for.h bugprone-unchecked-optional-access std::string doc = r.out->bytes; src/verbs_for.h bugprone-unsafe-functions std::rewind( capture ); src/verbs_for.h clang-analyzer-deadcode.DeadStores const std::size_t confidenceOwnBytes = forConf.attrs.size() + forConf.note.size(); src/verbs_grep.h clang-analyzer-deadcode.DeadStores const bool valueUses = d.valueUses; diff --git a/src/cloneidiom.h b/src/cloneidiom.h index f2fdfe56e..313a8894f 100644 --- a/src/cloneidiom.h +++ b/src/cloneidiom.h @@ -1203,20 +1203,21 @@ namespace cloneidiomdetail { // One member's classification inputs. `ids` is filled only when the shape was recognized — the identifier -// set exists to answer condition (2), and there is nothing to answer when (1) already failed. +// set exists to answer condition (2), and there is nothing to answer when (1) already failed. Widest members first, the +// one-byte fields last, so the struct carries no padding holes. struct MemberShape { - CloneIdiom idiom = CloneIdiom::None; std::vector ids; // sorted + unique FNV-1a of every non-keyword identifier in the body (one-statement, call-sequence: the narrowed set) - std::uint64_t alpha = 0; // one-statement and call-sequence only: the parameter-renamed body hash (OneStatementFacts::alpha) - std::uint32_t fileId = 0; std::string scope; - bool read = false; // the body was read; an unread member proves no operand difference std::vector literals; // idiomLiteralSet of the body std::vector valueIds; // the subset of `ids` used as a value somewhere (operand path (6)) std::vector callIds; // the subset of `ids` called somewhere, `f(` not after `.`/`->` (operand path (6)) - bool literalArg = false; // a compared literal is a direct argument of some call (operand path (5)) std::vector paramTypes; // IdiomParams::types, in parameter order + std::uint64_t alpha = 0; // one-statement and call-sequence only: the parameter-renamed body hash (OneStatementFacts::alpha) + std::uint32_t fileId = 0; + CloneIdiom idiom = CloneIdiom::None; + bool read = false; // the body was read; an unread member proves no operand difference + bool literalArg = false; // a compared literal is a direct argument of some call (operand path (5)) bool typed = false; // IdiomParams::typed }; diff --git a/src/defattrib.h b/src/defattrib.h index 7782e21db..c29efea2d 100644 --- a/src/defattrib.h +++ b/src/defattrib.h @@ -859,7 +859,7 @@ inline std::vector defGroupsSilent( const DefGroups& groups, const RowDefT std::vector silent( groups.size(), 0 ); for( std::size_t k = 0; k < groups.size(); ++k ) { - silent[k] = groups.untied[k] && !named[k]; + silent[k] = static_cast( groups.untied[k] && !named[k] ); } return silent; } diff --git a/src/defectshape.h b/src/defectshape.h index 13e2f5803..60ab60fcc 100644 --- a/src/defectshape.h +++ b/src/defectshape.h @@ -2094,7 +2094,7 @@ class Script } // ── the index: scopes, functions, assignments, writers, judgments ────────────────────────────────────────────── - void visit( std::uint32_t list, std::uint32_t scope, std::vector reach ) + void visit( std::uint32_t list, std::uint32_t scope, const std::vector& reach ) { if( list == kNone ) { @@ -3968,19 +3968,20 @@ inline void Script::unreadRcFileSites( std::vector& at ) const } } const std::uint32_t scope = scope_[c]; + const auto ranRcFileBefore = [ & ] // a run node before this one, in its scope, that ran an rc file + { + for( std::uint32_t d = 0; d < a_.facts.size(); ++d ) + { + if( a_.facts[d].seen && scope_[d] == scope && node( d ).pos < n.pos && isRun( d ) && a_.facts[d].cons.how.rfind( "rc file", 0 ) == 0 ) + { + return true; + } + } + return false; + }; const bool afterRun = std::any_of( a_.calls.begin(), a_.calls.end(), [ & ]( const sh::Call& call ) { return call.node != kNone && scope_[call.node] == scope && call.how.rfind( "rc file", 0 ) == 0 && node( call.node ).pos < n.pos; } ) - || [ & ] - { - for( std::uint32_t d = 0; d < a_.facts.size(); ++d ) - { - if( a_.facts[d].seen && scope_[d] == scope && node( d ).pos < n.pos && isRun( d ) && a_.facts[d].cons.how.rfind( "rc file", 0 ) == 0 ) - { - return true; - } - } - return false; - }(); + || ranRcFileBefore(); if( target.empty() || !afterRun ) { continue; @@ -4973,6 +4974,7 @@ inline SwitchArms switchArmsOf( std::string_view src, const std::vector& to afterLbl = false; } std::vector ends; + ends.reserve( arms.ranges.size() ); for( const auto& [ first, end ] : arms.ranges ) { ends.push_back( armEndOf( src, toks, first, end ) ); @@ -5508,6 +5510,7 @@ inline std::vector pyChainConsts( std::string_view src, const std::vect inline std::pair pyUnhandledOutcome( bool isMatch, std::string_view subject, const std::vector& consts, const std::vector& enums ) { std::vector named; + named.reserve( consts.size() ); for( const PyConst& c : consts ) { named.push_back( c.text ); diff --git a/src/foranswerfirst.h b/src/foranswerfirst.h index 6c423ef18..6bf8c4757 100644 --- a/src/foranswerfirst.h +++ b/src/foranswerfirst.h @@ -93,10 +93,10 @@ struct AnswerFirstFallback }; void disclose( DisclosureWhy why ) noexcept { - rw::emitTo( stderr, "ripwire: --legend=last: {}\n", - why == DisclosureWhy::SizeChanged - ? "the permuted answer changed size, so the original order is served — the answer is complete either way" - : "the answer did not buffer whole, so it is served in the default order — the answer is complete either way" ); + // literal text, no formatting: emitRaw cannot throw where emitTo's std::print could (bad_alloc) out of this noexcept sink + rw::emitRaw( stderr, why == DisclosureWhy::SizeChanged + ? "ripwire: --legend=last: the permuted answer changed size, so the original order is served — the answer is complete either way\n" + : "ripwire: --legend=last: the answer did not buffer whole, so it is served in the default order — the answer is complete either way\n" ); } }; diff --git a/src/formanifest.h b/src/formanifest.h index 008dc81f6..3f8bd4ca9 100644 --- a/src/formanifest.h +++ b/src/formanifest.h @@ -589,7 +589,7 @@ inline std::optional> cmakeCallStart( std for( const auto& [cmd, kind] : kCMakeCommands ) { const bool named = t.size() > cmd.size() && std::ranges::equal( t.substr( 0, cmd.size() ), cmd, []( char a, char b ) - { return lexLowerByte( static_cast( a ) ) == b; } ); + { return lexLowerByte( static_cast( a ) ) == static_cast( b ); } ); const std::string_view paren = named ? trimWs( t.substr( cmd.size() ) ) : std::string_view(); if( paren.starts_with( '(' ) ) { @@ -1232,6 +1232,7 @@ inline DefiningLine definingLine( std::string_view txt, const std::vector& features, std::vector& touch ) { std::vector forms; // HOISTING: per feature, its spellings, built once + forms.reserve( features.size() ); for( const std::string_view f : features ) { forms.push_back( { std::string( f ), "`" + std::string( f ) + "`", "\"" + std::string( f ) + "\"" } ); diff --git a/src/ingest_binds.h b/src/ingest_binds.h index 0e0bac825..93b831a91 100644 --- a/src/ingest_binds.h +++ b/src/ingest_binds.h @@ -2978,7 +2978,7 @@ inline void emitShadowParamDecls( TSNode params, std::uint32_t fileId, Lang lang // and decltype types write nothing (writtenTypeOf's own refusal), and pushRawBind drops the record. DeclType written = declTypeOfName( fieldChild( p, NodeField::Type ), src ); written.directDeclarator = cppDirectDeclarator( declarator ); - pushTypedBind( fileId, lang, paramDeclaratorVarName( declarator, src ), std::move( written ), BindSite{ ts_node_start_byte( p ), 0u, 0u }, + pushTypedBind( fileId, lang, paramDeclaratorVarName( declarator, src ), written, BindSite{ ts_node_start_byte( p ), 0u, 0u }, LocalBindKind::ParamType, binds ); } } diff --git a/src/ingest_jsimports.h b/src/ingest_jsimports.h index 1676cf79b..9435701b2 100644 --- a/src/ingest_jsimports.h +++ b/src/ingest_jsimports.h @@ -790,7 +790,7 @@ inline void captureJsImportFacts( TSNode root, Lang lang, std::uint32_t fileId, const bool isAlias = kinds.is( node, JsK::VariableDeclarator ) && aliasDecls.find( ts_node_start_byte( node ) ) != aliasDecls.end(); const JsScopeAt at{ kinds, ancestors, scratch.cur }; const JsDecl d = isAlias ? JsDecl{} : at.declarationOf( node ); - for( std::string name : jsPatternNames( d.binding, src ) ) + for( const std::string& name : jsPatternNames( d.binding, src ) ) { if( imported.find( name ) != imported.end() ) { recorder.add( node, LocalBindKind::JsShadow, name, d.scope ); } } diff --git a/src/memceiling.h b/src/memceiling.h index 150925a6e..7deaadef4 100644 --- a/src/memceiling.h +++ b/src/memceiling.h @@ -87,7 +87,7 @@ namespace rw::memceiling inline constexpr std::uint64_t kMiB = 1024ull * 1024ull; inline constexpr std::uint64_t kFloorMiB = 64; // memguard's own floor: below it a value is a typo -inline constexpr std::size_t kLargeBytes = 256 * 1024; // largealloc's kMinBytes: these read on every call +inline constexpr std::size_t kLargeBytes = std::size_t( 256 ) * 1024; // largealloc's kMinBytes: these read on every call inline constexpr std::uint64_t kSmallStrideBytes = 64ull * kMiB; // per thread, small allocations between two readings inline constexpr int kRefusalExit = 5; // the memory-refusal exit (memguard.h) inline constexpr std::size_t kLabelBytes = 96; diff --git a/src/memstats.h b/src/memstats.h index 9a35ec314..302ac1f72 100644 --- a/src/memstats.h +++ b/src/memstats.h @@ -47,9 +47,10 @@ inline std::string reading( std::uint64_t bytes ) // one `[mem] phase= cur_mib= peak_mib=` line when RIPWIRE_STATS is set (either reading may be // `unavailable`) -inline void mark( std::string_view phase ) +inline void mark( const char* literal ) // a string literal: notePhase keeps the pointer, so it must be NUL-terminated and live forever { - memceiling::notePhase( phase.data() ); // every caller passes a string literal, so data() is NUL-terminated and lives forever + memceiling::notePhase( literal ); + const std::string_view phase( literal ); if( !enabled() ) { return; diff --git a/src/quality.h b/src/quality.h index 25bebb0e0..142efa70f 100644 --- a/src/quality.h +++ b/src/quality.h @@ -11579,6 +11579,7 @@ inline void appendTangleRatchet( std::vector& regs, const IngestResu TangleDetailReader& detailOf, Stamp&& stamp, std::string_view root, DeltaExtras& extras ) { std::vector paths; + paths.reserve( ratchetable.size() ); for( const auto& [ key, nowOfKey ] : ratchetable ) { paths.emplace_back( relForHash( ing.files[ ing.symbols[ nowOfKey->at ].fileId ], root ) ); diff --git a/src/receiverevidence.h b/src/receiverevidence.h index 2625adfdb..1b66da8ef 100644 --- a/src/receiverevidence.h +++ b/src/receiverevidence.h @@ -368,7 +368,8 @@ struct CallResultTypes const char bit = b.kind == LocalBindKind::TypeAlias ? kCppScopeAliased : b.var != "*" ? kCppScopeUsingDeclared : char( 0 ); if( bit != 0 ) { - cppScopeNames[ b.var ] |= bit; + char& names = cppScopeNames[ b.var ]; + names = static_cast( names | bit ); } } // a C++ using-directive / using-declaration, or (fix round 3) a C++ alias: the rows that carry their scope's span (model.h) diff --git a/src/resolve.h b/src/resolve.h index 2ea15800d..31b7661c0 100644 --- a/src/resolve.h +++ b/src/resolve.h @@ -9125,7 +9125,7 @@ struct Narrower // by-name reading std::optional unjudgedBase( std::size_t parent, const std::string& base, std::span from, bool drawn, bool baseDefined ) const { - const MeantClasses byName{ {}, walkMeant[ parent ].unbound }; + MeantClasses byName{ {}, walkMeant[ parent ].unbound }; // not const: the return below moves it if( drawn ) { return std::nullopt; // every edge drawn is the name collision: the evidence names a class the tree does not define here diff --git a/src/shstatus.h b/src/shstatus.h index 867d82e81..abb20d815 100644 --- a/src/shstatus.h +++ b/src/shstatus.h @@ -2133,6 +2133,7 @@ inline std::string varsAsGlob( std::string_view tgt ) inline void compilerOutputs( const Node& n, std::vector& targets ) { std::vector ws; + ws.reserve( n.words.size() ); for( const Word& w : n.words ) { ws.push_back( unq( w.text ) ); diff --git a/src/verbs_lint.h b/src/verbs_lint.h index 268d763d3..033951602 100644 --- a/src/verbs_lint.h +++ b/src/verbs_lint.h @@ -1101,7 +1101,7 @@ std::vector dedupeLintFindings( const EnclosingSymbolIndex& enclosing, const IngestResult& ing = enclosing.ing; HashMap seenRow; std::vector deduped; deduped.reserve( outs.size() ); - for( const LintOut& o : outs ) + for( LintOut& o : outs ) // `outs` is ours (moved in): a kept row moves out of it { const Symbol* e = enclosing( o.fileId, o.startByte ); std::string key; @@ -1117,7 +1117,7 @@ std::vector dedupeLintFindings( const EnclosingSymbolIndex& enclosing, continue; // same visible row already kept } seenRow.emplace( std::move( key ), 0 ); - deduped.push_back( o ); + deduped.push_back( std::move( o ) ); } return deduped; }