@@ -18,6 +18,8 @@ use iced::{
1818
1919use objc2:: rc:: Retained ;
2020use objc2_app_kit:: NSRunningApplication ;
21+ use rayon:: iter:: { IntoParallelRefIterator , ParallelIterator } ;
22+ use rayon:: slice:: ParallelSliceMut ;
2123
2224use std:: cmp:: min;
2325use std:: process:: Command ;
@@ -154,22 +156,22 @@ impl Tile {
154156 . show_icons
155157 . unwrap ( ) ;
156158
157- let home = std:: env:: var ( "HOME" ) . unwrap ( ) ;
159+ let user_local_path = std:: env:: var ( "HOME" ) . unwrap ( ) + "/Applications/" ;
158160
159- let mut apps = get_installed_apps ( "/Applications/" , store_icons) ;
160- apps. append ( & mut get_installed_apps (
161+ let paths = vec ! [
162+ "/Applications/" ,
163+ user_local_path. as_str( ) ,
161164 "/System/Applications/" ,
162- store_icons,
163- ) ) ;
164- apps. append ( & mut get_installed_apps (
165- home + "/Applications/" ,
166- store_icons,
167- ) ) ;
168- apps. append ( & mut get_installed_apps (
169165 "/System/Applications/Utilities/" ,
170- store_icons,
171- ) ) ;
172- apps. sort_by_key ( |x| x. name . len ( ) ) ;
166+ ] ;
167+
168+ let mut apps: Vec < App > = paths
169+ . par_iter ( )
170+ . map ( |path| get_installed_apps ( path, store_icons) )
171+ . flatten ( )
172+ . collect ( ) ;
173+
174+ apps. par_sort_by_key ( |x| x. name . len ( ) ) ;
173175
174176 (
175177 Self {
@@ -413,27 +415,29 @@ impl Tile {
413415 }
414416
415417 pub fn handle_search_query_changed ( & mut self ) {
416- let filter_vec = if self . query_lc . starts_with ( & self . prev_query_lc ) {
418+ let filter_vec: & Vec < App > = if self . query_lc . starts_with ( & self . prev_query_lc ) {
417419 self . prev_query_lc = self . query_lc . to_owned ( ) ;
418- & self . results . clone ( )
420+ & self . results
419421 } else {
420422 & self . options
421423 } ;
422424
423- self . results = vec ! [ ] ;
424- self . results . extend (
425- & mut filter_vec
426- . iter ( )
427- . filter ( |x| x. name_lc == self . query_lc )
428- . map ( |x| x. to_owned ( ) ) ,
429- ) ;
430-
431- self . results . extend (
432- & mut filter_vec
433- . iter ( )
434- . filter ( |x| x. name_lc != self . query_lc && x. name_lc . starts_with ( & self . query_lc ) )
435- . map ( |x| x. to_owned ( ) ) ,
436- ) ;
425+ let query = self . query_lc . clone ( ) ;
426+
427+ let mut exact: Vec < App > = filter_vec
428+ . par_iter ( )
429+ . filter ( |x| x. name_lc == query)
430+ . cloned ( )
431+ . collect ( ) ;
432+
433+ let mut prefix: Vec < App > = filter_vec
434+ . par_iter ( )
435+ . filter ( |x| x. name_lc != query && x. name_lc . starts_with ( & query) )
436+ . cloned ( )
437+ . collect ( ) ;
438+
439+ exact. append ( & mut prefix) ;
440+ self . results = exact;
437441 }
438442
439443 pub fn capture_frontmost ( & mut self ) {
0 commit comments