Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speedup item::best_pocket ~100% (2x as fast) and misc other wins too #55070

Merged
merged 1 commit into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12521,7 +12521,7 @@ bool item::is_soft() const
return false;
}

const std::map<material_id, int> mats = made_of();
const std::map<material_id, int> &mats = made_of();
return std::all_of( mats.begin(), mats.end(), []( const std::pair<material_id, int> &mid ) {
return mid.first->soft();
} );
Expand Down
9 changes: 2 additions & 7 deletions src/item_contents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,6 @@ void item_contents::force_insert_item( const item &it, item_pocket::pocket_type
std::pair<item_location, item_pocket *> item_contents::best_pocket( const item &it,
item_location &parent, const item *avoid, const bool allow_sealed, const bool ignore_settings )
{
if( !can_contain( it ).success() ) {
return { item_location(), nullptr };
}
std::pair<item_location, item_pocket *> ret;
ret.second = nullptr;
for( item_pocket &pocket : contents ) {
Expand Down Expand Up @@ -1191,8 +1188,7 @@ std::list<item *> item_contents::all_items_top( const std::function<bool( item_p
for( item_pocket &pocket : contents ) {
if( filter( pocket ) ) {
std::list<item *> contained_items = pocket.all_items_top();
all_items_internal.insert( all_items_internal.end(), contained_items.begin(),
contained_items.end() );
all_items_internal.splice( all_items_internal.end(), std::move( contained_items ) );
}
}
return all_items_internal;
Expand All @@ -1219,8 +1215,7 @@ std::list<const item *> item_contents::all_items_top( const
for( const item_pocket &pocket : contents ) {
if( filter( pocket ) ) {
std::list<const item *> contained_items = pocket.all_items_top();
all_items_internal.insert( all_items_internal.end(), contained_items.begin(),
contained_items.end() );
all_items_internal.splice( all_items_internal.end(), std::move( contained_items ) );
}
}
return all_items_internal;
Expand Down