Fix some copy instead of move Coverity CIDs - #13470
Conversation
CIDs fixed in this patch: 1664317 1664316 1664286 1664284 1663965 1660036 1658876 1658839 1658837 1658799 1654583 1654213 1654211 1654210 1654207 1654206 1645817 1645816 1645814 1645813 1645811 1645809 1645808 1645806 1645804 1645802 1645801 1645799 1645798 1645796 1645795 1644303 1644300 1644293 1644255 1644242 1644227 1644207
There was a problem hiding this comment.
Pull request overview
This PR addresses Coverity “copy instead of move” findings across ATS core, management components, traffic_ctl, and several plugins by introducing move semantics where values are no longer needed, and adding missing <utility> includes in most touched translation units.
Changes:
- Replace a number of
push_back/return-value copies withstd::move(...)/emplace_back(...)to avoid unnecessary copies. - Add
<utility>includes in many files to support newstd::moveusage. - Minor call-site adjustments to pass temporaries/locals via
std::move(e.g., params structs, shared_ptrs, YAML nodes).
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/traffic_ctl/jsonrpc/ctrl_yaml_codecs.h | Move LogEntry into response vector; add <utility>. |
| src/traffic_ctl/CtrlCommands.cc | Move CLI-derived strings/params into locals/requests; add <utility> and reorder <csignal>. |
| src/traffic_cache_tool/CacheDefs.h | Move per-line regex strings into vector; add <utility>. |
| src/records/unit_tests/test_ReloadDirectives.cc | Move shared_ptr task into ConfigContext. |
| src/proxy/Plugin.cc | Avoid copying plugin path into PluginLoadSummary entry; add <utility>. |
| src/proxy/logging/LogField.cc | Move std::function marshal/unmarshal callables into members. |
| src/mgmt/rpc/handlers/config/Configuration.cc | Move resolved config keys into valid_configs; add <utility>. |
| src/mgmt/config/ReloadCoordinator.cc | Move shared_ptr subtasks/contexts where appropriate. |
| src/mgmt/config/ConfigReloadTrace.cc | Move shared_ptr into ConfigContext / progress tracker; add <utility>. |
| src/iocore/net/unit_tests/test_SSLSNIConfig.cc | Move test item into params vector; add <utility>. |
| src/iocore/cache/CacheDir.cc | Move captured stripe index vector into shutdown worker lambda; add <utility>. |
| src/config/unit_tests/test_ssl_multicert.cc | Move multicert entries into test vectors; add <utility>. |
| src/config/ssl_multicert.cc | Move ConfigResult payload/errata on return paths. |
| src/api/InkAPI.cc | Move marshal callback into stored lambda capture; add <utility>. |
| plugins/webp_transform/ImageTransform.cc | Move content-type string into ImageTransform ctor. |
| plugins/stats_over_http/stats_over_http.cc | Move parse_metric_v2 return parts; add <utility>. |
| plugins/prefetch/path.cc | Move normalized path into output struct; add <utility>. |
| plugins/experimental/txn_box/plugin/src/ip_space.cc | Move YAML node when passing into column-definition routine. |
| plugins/experimental/txn_box/plugin/src/Config.cc | Move YAML node when invoking directive loaders; add <utility>. |
| plugins/experimental/txn_box/plugin/src/Comparison.cc | Move YAML nodes into case-loading; add <utility>. |
| plugins/experimental/jax_fingerprint/ja4h/test.cc | Move method/fields into mock datasource; add <utility>. |
| plugins/experimental/jax_fingerprint/ja4/test.cc | Move first ALPN into mock datasource; add <utility>. |
| plugins/experimental/filter_body/filter_body.cc | Move header/condition structs into vectors; add <utility>. |
| include/mgmt/config/ConfigReloadTrace.h | Move parent shared_ptr into member in ctor (but missing <utility> include). |
| include/iocore/net/ConnectionTracker.h | Move metric-name string on return; add <utility>. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 25 out of 25 changed files in this pull request and generated no new comments.
Suppressed comments (1)
include/iocore/net/ConnectionTracker.h:433
- Using std::move(metric_name) in a return expression is a pessimizing move: it blocks NRVO/copy-elision opportunities for the local string and adds noise. This can be fixed by using an explicit if/return and returning metric_name normally (the compiler will elide or move).
Warning("Invalid matching type to add to per_server.connections metrics");
}
return metric_prefix.empty() ? std::move(metric_name) : metric_prefix + "." + metric_name;
|
Copilot's comment about moving the ternary operand blocking NRVO/copy elision is possibly the most interesting dubious comment I've seen from Copilot to date. It has low confidence, which is good, because it should. This is a very subtle trap in C++: the original ternary expression has an l-value operand and an r-value operand, so it is guaranteed to evaluate to an r-value. Therefore, the ternary expression is actually forced to cause a temporary copy of |
CIDs fixed in this patch:
1664317
1664316
1664286
1664284
1663965
1660036
1658876
1658839
1658837
1658799
1654583
1654213
1654211
1654210
1654207
1654206
1645817
1645816
1645814
1645813
1645811
1645809
1645808
1645806
1645804
1645802
1645801
1645799
1645798
1645796
1645795
1644303
1644300
1644293
1644255
1644242
1644227
1644207