@@ -9,6 +9,7 @@ use objdiff_core::{
99 diff:: { ObjDiff , ObjSymbolDiff } ,
1010 obj:: { ObjInfo , ObjSection , ObjSectionKind , ObjSymbol , ObjSymbolFlags , SymbolRef } ,
1111} ;
12+ use regex:: { Regex , RegexBuilder } ;
1213
1314use crate :: {
1415 app:: AppConfigRef ,
@@ -44,6 +45,7 @@ pub struct DiffViewState {
4445 pub symbol_state : SymbolViewState ,
4546 pub function_state : FunctionViewState ,
4647 pub search : String ,
48+ pub search_regex : Option < Regex > ,
4749 pub queue_build : bool ,
4850 pub build_running : bool ,
4951 pub scratch_available : bool ,
@@ -300,22 +302,21 @@ fn symbol_ui(
300302 ret
301303}
302304
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+ }
311312}
312313
313314#[ must_use]
314315fn symbol_list_ui (
315316 ui : & mut Ui ,
316317 obj : & ( ObjInfo , ObjDiff ) ,
317318 state : & mut SymbolViewState ,
318- lower_search : & str ,
319+ search_regex : Option < & Regex > ,
319320 appearance : & Appearance ,
320321 left : bool ,
321322) -> Option < View > {
@@ -328,6 +329,9 @@ fn symbol_list_ui(
328329 if !obj. 0 . common . is_empty ( ) {
329330 CollapsingHeader :: new ( ".comm" ) . default_open ( true ) . show ( ui, |ui| {
330331 for ( symbol, symbol_diff) in obj. 0 . common . iter ( ) . zip ( & obj. 1 . common ) {
332+ if !symbol_matches_search ( symbol, search_regex) {
333+ continue ;
334+ }
331335 ret = ret. or ( symbol_ui (
332336 ui,
333337 symbol,
@@ -375,7 +379,7 @@ fn symbol_list_ui(
375379 for ( symbol, symbol_diff) in
376380 section. symbols . iter ( ) . zip ( & section_diff. symbols ) . rev ( )
377381 {
378- if !symbol_matches_search ( symbol, lower_search ) {
382+ if !symbol_matches_search ( symbol, search_regex ) {
379383 continue ;
380384 }
381385 ret = ret. or ( symbol_ui (
@@ -392,7 +396,7 @@ fn symbol_list_ui(
392396 for ( symbol, symbol_diff) in
393397 section. symbols . iter ( ) . zip ( & section_diff. symbols )
394398 {
395- if !symbol_matches_search ( symbol, lower_search ) {
399+ if !symbol_matches_search ( symbol, search_regex ) {
396400 continue ;
397401 }
398402 ret = ret. or ( symbol_ui (
@@ -446,7 +450,7 @@ fn missing_obj_ui(ui: &mut Ui, appearance: &Appearance) {
446450}
447451
448452pub 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;
450454 let Some ( result) = build else {
451455 return ;
452456 } ;
@@ -481,7 +485,17 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
481485 }
482486 } ) ;
483487
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+ }
485499 } ,
486500 ) ;
487501
@@ -519,7 +533,6 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
519533
520534 // Table
521535 let mut ret = None ;
522- let lower_search = search. to_ascii_lowercase ( ) ;
523536 StripBuilder :: new ( ui) . size ( Size :: remainder ( ) ) . vertical ( |mut strip| {
524537 strip. strip ( |builder| {
525538 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
531544 ui,
532545 obj,
533546 symbol_state,
534- & lower_search ,
547+ search_regex . as_ref ( ) ,
535548 appearance,
536549 true ,
537550 ) ) ;
@@ -551,7 +564,7 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
551564 ui,
552565 obj,
553566 symbol_state,
554- & lower_search ,
567+ search_regex . as_ref ( ) ,
555568 appearance,
556569 false ,
557570 ) ) ;
0 commit comments