Add some uses of std::move in constructors and simple functions for pass-by-value arguments

This commit is contained in:
Tim Wojtulewicz 2023-11-27 11:41:48 -07:00
parent 1e33467844
commit ef5b169acd
9 changed files with 15 additions and 14 deletions

View file

@ -151,7 +151,7 @@ public:
// delete values. // delete values.
class DeltaSetSetEntry : public ValDelta { class DeltaSetSetEntry : public ValDelta {
public: public:
DeltaSetSetEntry(const ValTrace* _vt, ValPtr _index) : ValDelta(_vt), index(_index) {} DeltaSetSetEntry(const ValTrace* _vt, ValPtr _index) : ValDelta(_vt), index(std::move(_index)) {}
std::string Generate(ValTraceMgr* vtm) const override; std::string Generate(ValTraceMgr* vtm) const override;
bool NeedsLHS() const override { return false; } bool NeedsLHS() const override { return false; }
@ -166,7 +166,7 @@ private:
class DeltaSetTableEntry : public ValDelta { class DeltaSetTableEntry : public ValDelta {
public: public:
DeltaSetTableEntry(const ValTrace* _vt, ValPtr _index, ValPtr _new_val) DeltaSetTableEntry(const ValTrace* _vt, ValPtr _index, ValPtr _new_val)
: ValDelta(_vt), index(_index), new_val(std::move(_new_val)) {} : ValDelta(_vt), index(std::move(_index)), new_val(std::move(_new_val)) {}
std::string Generate(ValTraceMgr* vtm) const override; std::string Generate(ValTraceMgr* vtm) const override;

View file

@ -3057,7 +3057,7 @@ ListExprPtr expand_op(ListExprPtr op, const TypePtr& t) {
TableConstructorExpr::TableConstructorExpr(ListExprPtr constructor_list, TableConstructorExpr::TableConstructorExpr(ListExprPtr constructor_list,
std::unique_ptr<std::vector<AttrPtr>> arg_attrs, TypePtr arg_type, std::unique_ptr<std::vector<AttrPtr>> arg_attrs, TypePtr arg_type,
AttributesPtr arg_attrs2) AttributesPtr arg_attrs2)
: UnaryExpr(EXPR_TABLE_CONSTRUCTOR, expand_op(constructor_list, arg_type)) { : UnaryExpr(EXPR_TABLE_CONSTRUCTOR, expand_op(std::move(constructor_list), arg_type)) {
if ( IsError() ) if ( IsError() )
return; return;

View file

@ -1563,7 +1563,7 @@ public:
* @return True if the element was inserted or false if the element was * @return True if the element was inserted or false if the element was
* the wrong type. * the wrong type.
*/ */
bool Append(ValPtr element) { return Insert(Size(), element); } bool Append(ValPtr element) { return Insert(Size(), std::move(element)); }
// Removes an element at a specific position. // Removes an element at a specific position.
bool Remove(unsigned int index); bool Remove(unsigned int index);

View file

@ -74,7 +74,7 @@ public:
*/ */
Packet(int link_type, pkt_timeval* ts, uint32_t caplen, uint32_t len, const u_char* data, bool copy = false, Packet(int link_type, pkt_timeval* ts, uint32_t caplen, uint32_t len, const u_char* data, bool copy = false,
std::string tag = "") { std::string tag = "") {
Init(link_type, ts, caplen, len, data, copy, tag); Init(link_type, ts, caplen, len, data, copy, std::move(tag));
} }
/** /**

View file

@ -9,9 +9,8 @@
using namespace zeek::packet_analysis; using namespace zeek::packet_analysis;
Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype) Component::Component(const std::string& name, factory_callback arg_factory, Tag::subtype_t arg_subtype)
: plugin::Component(plugin::component::PACKET_ANALYZER, name, arg_subtype, packet_mgr->GetTagType()) { : plugin::Component(plugin::component::PACKET_ANALYZER, name, arg_subtype, packet_mgr->GetTagType()),
factory = arg_factory; factory(std::move(arg_factory)) {}
}
void Component::Initialize() { void Component::Initialize() {
InitializeTag(); InitializeTag();

View file

@ -263,7 +263,9 @@ void IPBasedAnalyzer::DumpPortDebug() {
TableValPtr IPBasedAnalyzer::ignore_checksums_nets_table = nullptr; TableValPtr IPBasedAnalyzer::ignore_checksums_nets_table = nullptr;
void IPBasedAnalyzer::SetIgnoreChecksumsNets(TableValPtr t) { IPBasedAnalyzer::ignore_checksums_nets_table = t; } void IPBasedAnalyzer::SetIgnoreChecksumsNets(TableValPtr t) {
IPBasedAnalyzer::ignore_checksums_nets_table = std::move(t);
}
TableValPtr IPBasedAnalyzer::GetIgnoreChecksumsNets() { TableValPtr IPBasedAnalyzer::GetIgnoreChecksumsNets() {
if ( ! IPBasedAnalyzer::ignore_checksums_nets_table ) if ( ! IPBasedAnalyzer::ignore_checksums_nets_table )

View file

@ -185,7 +185,7 @@ namespace detail {
IPTunnelTimer::IPTunnelTimer(double t, IPTunnelAnalyzer::IPPair p, IPTunnelAnalyzer* analyzer) IPTunnelTimer::IPTunnelTimer(double t, IPTunnelAnalyzer::IPPair p, IPTunnelAnalyzer* analyzer)
: Timer(t + BifConst::Tunnel::ip_tunnel_timeout, zeek::detail::TIMER_IP_TUNNEL_INACTIVITY), : Timer(t + BifConst::Tunnel::ip_tunnel_timeout, zeek::detail::TIMER_IP_TUNNEL_INACTIVITY),
tunnel_idx(p), tunnel_idx(std::move(p)),
analyzer(analyzer) {} analyzer(analyzer) {}
void IPTunnelTimer::Dispatch(double t, bool is_expire) { void IPTunnelTimer::Dispatch(double t, bool is_expire) {

View file

@ -71,7 +71,7 @@ public:
// but not have an associated expression, if the point-of-definition // but not have an associated expression, if the point-of-definition
// is the end of a confluence block. // is the end of a confluence block.
const ExprPtr& DefExprAfter() const { return def_expr; } const ExprPtr& DefExprAfter() const { return def_expr; }
void SetDefExpr(ExprPtr e) { def_expr = e; } void SetDefExpr(ExprPtr e) { def_expr = std::move(e); }
// Used for debugging. // Used for debugging.
void Dump() const; void Dump() const;
@ -107,7 +107,7 @@ protected:
class IDInitInfo { class IDInitInfo {
public: public:
IDInitInfo(const ID* _id, ExprPtr _init, InitClass _ic) : id(_id), init(_init), ic(_ic) {} IDInitInfo(const ID* _id, ExprPtr _init, InitClass _ic) : id(_id), init(std::move(_init)), ic(_ic) {}
const ID* Id() const { return id; } const ID* Id() const { return id; }
const ExprPtr& Init() const { return init; } const ExprPtr& Init() const { return init; }

View file

@ -172,8 +172,8 @@ protected:
class CoalescedScriptFunc : public ScriptFunc { class CoalescedScriptFunc : public ScriptFunc {
public: public:
CoalescedScriptFunc(StmtPtr merged_body, ScopePtr scope, ScriptFuncPtr orig_func) CoalescedScriptFunc(StmtPtr merged_body, ScopePtr scope, ScriptFuncPtr orig_func)
: ScriptFunc(orig_func->Name(), orig_func->GetType(), {merged_body}, {0}), orig_func(orig_func) { : ScriptFunc(orig_func->Name(), orig_func->GetType(), {std::move(merged_body)}, {0}), orig_func(orig_func) {
SetScope(scope); SetScope(std::move(scope));
}; };
ValPtr Invoke(zeek::Args* args, Frame* parent) const override { ValPtr Invoke(zeek::Args* args, Frame* parent) const override {