@@ -28,12 +28,12 @@ use objc2_app_kit::NSRunningApplication;
2828use rayon:: iter:: { IntoParallelRefIterator , ParallelIterator } ;
2929use tray_icon:: TrayIcon ;
3030
31+ use std:: collections:: HashMap ;
3132use std:: fmt:: Debug ;
3233use std:: fs;
33- use std:: ops :: Bound ;
34+ use std:: path :: Path ;
3435use std:: str:: FromStr ;
3536use std:: time:: Duration ;
36- use std:: { collections:: BTreeMap , path:: Path } ;
3737
3838/// This is a wrapper around the sender to disable dropping
3939#[ derive( Clone , Debug ) ]
@@ -47,17 +47,21 @@ impl Drop for ExtSender {
4747/// All the indexed apps that rustcast can search for
4848#[ derive( Clone , Debug ) ]
4949struct AppIndex {
50- by_name : BTreeMap < String , App > ,
50+ by_name : HashMap < String , App > ,
5151}
5252
5353impl AppIndex {
5454 /// Search for an element in the index that starts with the provided prefix
55- fn search_prefix < ' a > ( & ' a self , prefix : & ' a str ) -> impl Iterator < Item = & ' a App > + ' a {
56- self . by_name
57- . range :: < str , _ > ( ( Bound :: Included ( prefix) , Bound :: Unbounded ) )
58- . take_while ( move |( k, _) | k. starts_with ( prefix) )
59- . map ( |( _, v) | v)
55+ fn search_prefix < ' a > ( & ' a self , prefix : & ' a str ) -> impl ParallelIterator < Item = & ' a App > + ' a {
56+ self . by_name . par_iter ( ) . filter_map ( move |( name, app) | {
57+ if name. starts_with ( prefix) || name. contains ( format ! ( " {prefix}" ) . as_str ( ) ) {
58+ Some ( app)
59+ } else {
60+ None
61+ }
62+ } )
6063 }
64+
6165 fn update_ranking ( & mut self , name : & str ) {
6266 let app = match self . by_name . get_mut ( name) {
6367 Some ( a) => a,
@@ -69,18 +73,18 @@ impl AppIndex {
6973
7074 fn empty ( ) -> AppIndex {
7175 AppIndex {
72- by_name : BTreeMap :: new ( ) ,
76+ by_name : HashMap :: new ( ) ,
7377 }
7478 }
7579
7680 /// Factory function for creating
7781 pub fn from_apps ( options : Vec < App > ) -> Self {
78- let mut bmap = BTreeMap :: new ( ) ;
82+ let mut hmap = HashMap :: new ( ) ;
7983 for app in options {
80- bmap . insert ( app. search_name . clone ( ) , app) ;
84+ hmap . insert ( app. search_name . clone ( ) , app) ;
8185 }
8286
83- AppIndex { by_name : bmap }
87+ AppIndex { by_name : hmap }
8488 }
8589}
8690
0 commit comments