@@ -40,6 +40,8 @@ import {BORDER_SIZE, COLORS, NATIVE_EVENT_HEIGHT} from './constants';
4040const ROW_WITH_BORDER_HEIGHT = NATIVE_EVENT_HEIGHT + BORDER_SIZE ;
4141
4242export class ComponentMeasuresView extends View {
43+ _cachedSearchMatches : Map < string , boolean > ;
44+ _cachedSearchRegExp: RegExp | null = null ;
4345 _hoveredComponentMeasure: ReactComponentMeasure | null = null ;
4446 _intrinsicSize: IntrinsicSize ;
4547 _profilerData: ReactProfilerData ;
@@ -58,6 +60,9 @@ export class ComponentMeasuresView extends View {
5860 this . _profilerData = profilerData ;
5961 this . _viewState = viewState ;
6062
63+ this . _cachedSearchMatches = new Map ( ) ;
64+ this . _cachedSearchRegExp = null ;
65+
6166 viewState . onSearchRegExpStateChange ( ( ) => {
6267 this . setNeedsDisplay ( ) ;
6368 } ) ;
@@ -166,11 +171,20 @@ export class ComponentMeasuresView extends View {
166171 }
167172 }
168173
169- const searchRegExp = this . _viewState . searchRegExp ;
170- const isSearchMatch =
171- searchRegExp !== null &&
172- componentMeasure . componentName . match ( searchRegExp ) ;
173- if ( isSearchMatch ) {
174+ let isMatch = false ;
175+ const cachedSearchRegExp = this . _cachedSearchRegExp ;
176+ if ( cachedSearchRegExp !== null ) {
177+ const cachedSearchMatches = this . _cachedSearchMatches ;
178+ const cachedValue = cachedSearchMatches . get ( componentName ) ;
179+ if ( cachedValue != null ) {
180+ isMatch = cachedValue ;
181+ } else {
182+ isMatch = componentName . match ( cachedSearchRegExp ) !== null ;
183+ cachedSearchMatches . set ( componentName , isMatch ) ;
184+ }
185+ }
186+
187+ if ( isMatch ) {
174188 context . fillStyle = COLORS . SEARCH_RESULT_FILL ;
175189 }
176190
@@ -198,6 +212,12 @@ export class ComponentMeasuresView extends View {
198212 visibleArea,
199213 } = this ;
200214
215+ const searchRegExp = this . _viewState . searchRegExp ;
216+ if ( this . _cachedSearchRegExp !== searchRegExp ) {
217+ this . _cachedSearchMatches = new Map ( ) ;
218+ this . _cachedSearchRegExp = searchRegExp ;
219+ }
220+
201221 context . fillStyle = COLORS . BACKGROUND ;
202222 context . fillRect (
203223 visibleArea . origin . x ,
0 commit comments