From 5ae50e578d4f9f52776f067871f36d03b18b1bad Mon Sep 17 00:00:00 2001 From: Brambor Date: Sat, 14 Dec 2024 18:34:47 +0100 Subject: [PATCH] filter: use the O(log(n)) instead of O(n) method --- src/item_search.cpp | 6 ++---- src/recipe_dictionary.cpp | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/item_search.cpp b/src/item_search.cpp index 1b4e7593c76e3..eaf7fcb54276a 100644 --- a/src/item_search.cpp +++ b/src/item_search.cpp @@ -34,10 +34,8 @@ static std::function< bool( const item & )> can_contain_filter( std::string_view } // copy the debug item template (itype), put it on heap so the itype pointer doesn't move // TODO unique_ptr - std::shared_ptr filtered_fake_itype = std::make_shared( *( item_controller->find( []( - const itype & i ) { - return i.get_id() == STATIC( itype_id( "debug_item_search" ) ); - } )[0] ) ); + std::shared_ptr filtered_fake_itype = std::make_shared + ( *item_controller->find_template( STATIC( itype_id( "debug_item_search" ) ) ) ); item filtered_fake_item = set_function( filtered_fake_itype.get(), uni ); // pass to keep filtered_fake_itype valid until lambda capture is destroyed (while item is needed) return [filtered_fake_itype, filtered_fake_item]( const item & i ) { diff --git a/src/recipe_dictionary.cpp b/src/recipe_dictionary.cpp index 07c39caca347f..247ff2200e296 100644 --- a/src/recipe_dictionary.cpp +++ b/src/recipe_dictionary.cpp @@ -209,9 +209,8 @@ static Unit can_contain_filter( std::string_view hint, std::string_view txt, Uni popup( err.what() ); } // copy the debug item template (itype) - filtered_fake_itype = itype( *( item_controller->find( []( const itype & i ) { - return i.get_id() == STATIC( itype_id( "debug_item_search" ) ); - } )[0] ) ); + filtered_fake_itype = itype( *item_controller->find_template( STATIC( + itype_id( "debug_item_search" ) ) ) ); return uni; }