Skip to content

Commit

Permalink
Use move semantics in inventory::add_item() (#55100)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrettDong authored Feb 4, 2022
1 parent 1c9a584 commit 0e70699
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ item &inventory::add_item( item newit, bool keep_invlet, bool assign_invlet, boo
} else {
newit.invlet = it_ref->invlet;
}
elem.push_back( newit );
elem.emplace_back( std::move( newit ) );
return elem.back();
} else if( keep_invlet && assign_invlet && it_ref->invlet == newit.invlet ) {
// If keep_invlet is true, we'll be forcing other items out of their current invlet.
Expand All @@ -316,9 +316,7 @@ item &inventory::add_item( item newit, bool keep_invlet, bool assign_invlet, boo
}
update_cache_with_item( newit );

std::list<item> newstack;
newstack.push_back( newit );
items.push_back( newstack );
items.emplace_back( std::list<item> { std::move( newit ) } );
return items.back().back();
}

Expand Down

0 comments on commit 0e70699

Please sign in to comment.