@@ -9,6 +9,7 @@ use objdiff_core::{
9
9
diff:: { ObjDiff , ObjSymbolDiff } ,
10
10
obj:: { ObjInfo , ObjSection , ObjSectionKind , ObjSymbol , ObjSymbolFlags , SymbolRef } ,
11
11
} ;
12
+ use regex:: { Regex , RegexBuilder } ;
12
13
13
14
use crate :: {
14
15
app:: AppConfigRef ,
@@ -44,6 +45,7 @@ pub struct DiffViewState {
44
45
pub symbol_state : SymbolViewState ,
45
46
pub function_state : FunctionViewState ,
46
47
pub search : String ,
48
+ pub search_regex : Option < Regex > ,
47
49
pub queue_build : bool ,
48
50
pub build_running : bool ,
49
51
pub scratch_available : bool ,
@@ -300,22 +302,21 @@ fn symbol_ui(
300
302
ret
301
303
}
302
304
303
- fn symbol_matches_search ( symbol : & ObjSymbol , search_str : & str ) -> bool {
304
- search_str. is_empty ( )
305
- || symbol. name . contains ( search_str)
306
- || symbol
307
- . demangled_name
308
- . as_ref ( )
309
- . map ( |s| s. to_ascii_lowercase ( ) . contains ( search_str) )
310
- . unwrap_or ( false )
305
+ fn symbol_matches_search ( symbol : & ObjSymbol , search_regex : Option < & Regex > ) -> bool {
306
+ if let Some ( search_regex) = search_regex {
307
+ search_regex. is_match ( & symbol. name )
308
+ || symbol. demangled_name . as_ref ( ) . map ( |s| search_regex. is_match ( s) ) . unwrap_or ( false )
309
+ } else {
310
+ true
311
+ }
311
312
}
312
313
313
314
#[ must_use]
314
315
fn symbol_list_ui (
315
316
ui : & mut Ui ,
316
317
obj : & ( ObjInfo , ObjDiff ) ,
317
318
state : & mut SymbolViewState ,
318
- lower_search : & str ,
319
+ search_regex : Option < & Regex > ,
319
320
appearance : & Appearance ,
320
321
left : bool ,
321
322
) -> Option < View > {
@@ -328,6 +329,9 @@ fn symbol_list_ui(
328
329
if !obj. 0 . common . is_empty ( ) {
329
330
CollapsingHeader :: new ( ".comm" ) . default_open ( true ) . show ( ui, |ui| {
330
331
for ( symbol, symbol_diff) in obj. 0 . common . iter ( ) . zip ( & obj. 1 . common ) {
332
+ if !symbol_matches_search ( symbol, search_regex) {
333
+ continue ;
334
+ }
331
335
ret = ret. or ( symbol_ui (
332
336
ui,
333
337
symbol,
@@ -375,7 +379,7 @@ fn symbol_list_ui(
375
379
for ( symbol, symbol_diff) in
376
380
section. symbols . iter ( ) . zip ( & section_diff. symbols ) . rev ( )
377
381
{
378
- if !symbol_matches_search ( symbol, lower_search ) {
382
+ if !symbol_matches_search ( symbol, search_regex ) {
379
383
continue ;
380
384
}
381
385
ret = ret. or ( symbol_ui (
@@ -392,7 +396,7 @@ fn symbol_list_ui(
392
396
for ( symbol, symbol_diff) in
393
397
section. symbols . iter ( ) . zip ( & section_diff. symbols )
394
398
{
395
- if !symbol_matches_search ( symbol, lower_search ) {
399
+ if !symbol_matches_search ( symbol, search_regex ) {
396
400
continue ;
397
401
}
398
402
ret = ret. or ( symbol_ui (
@@ -446,7 +450,7 @@ fn missing_obj_ui(ui: &mut Ui, appearance: &Appearance) {
446
450
}
447
451
448
452
pub fn symbol_diff_ui ( ui : & mut Ui , state : & mut DiffViewState , appearance : & Appearance ) {
449
- let DiffViewState { build, current_view, symbol_state, search, .. } = state;
453
+ let DiffViewState { build, current_view, symbol_state, search, search_regex , .. } = state;
450
454
let Some ( result) = build else {
451
455
return ;
452
456
} ;
@@ -481,7 +485,17 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
481
485
}
482
486
} ) ;
483
487
484
- TextEdit :: singleline ( search) . hint_text ( "Filter symbols" ) . ui ( ui) ;
488
+ if TextEdit :: singleline ( search) . hint_text ( "Filter symbols" ) . ui ( ui) . changed ( ) {
489
+ if search. is_empty ( ) {
490
+ * search_regex = None ;
491
+ } else if let Ok ( regex) =
492
+ RegexBuilder :: new ( search) . case_insensitive ( true ) . build ( )
493
+ {
494
+ * search_regex = Some ( regex) ;
495
+ } else {
496
+ * search_regex = None ;
497
+ }
498
+ }
485
499
} ,
486
500
) ;
487
501
@@ -519,7 +533,6 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
519
533
520
534
// Table
521
535
let mut ret = None ;
522
- let lower_search = search. to_ascii_lowercase ( ) ;
523
536
StripBuilder :: new ( ui) . size ( Size :: remainder ( ) ) . vertical ( |mut strip| {
524
537
strip. strip ( |builder| {
525
538
builder. sizes ( Size :: remainder ( ) , 2 ) . horizontal ( |mut strip| {
@@ -531,7 +544,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
531
544
ui,
532
545
obj,
533
546
symbol_state,
534
- & lower_search ,
547
+ search_regex . as_ref ( ) ,
535
548
appearance,
536
549
true ,
537
550
) ) ;
@@ -551,7 +564,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
551
564
ui,
552
565
obj,
553
566
symbol_state,
554
- & lower_search ,
567
+ search_regex . as_ref ( ) ,
555
568
appearance,
556
569
false ,
557
570
) ) ;
0 commit comments