@@ -40,6 +40,8 @@ import {BORDER_SIZE, COLORS, NATIVE_EVENT_HEIGHT} from './constants';
40
40
const ROW_WITH_BORDER_HEIGHT = NATIVE_EVENT_HEIGHT + BORDER_SIZE ;
41
41
42
42
export class ComponentMeasuresView extends View {
43
+ _cachedSearchMatches : Map < string , boolean > ;
44
+ _cachedSearchRegExp: RegExp | null = null ;
43
45
_hoveredComponentMeasure: ReactComponentMeasure | null = null ;
44
46
_intrinsicSize: IntrinsicSize ;
45
47
_profilerData: ReactProfilerData ;
@@ -58,6 +60,9 @@ export class ComponentMeasuresView extends View {
58
60
this . _profilerData = profilerData ;
59
61
this . _viewState = viewState ;
60
62
63
+ this . _cachedSearchMatches = new Map ( ) ;
64
+ this . _cachedSearchRegExp = null ;
65
+
61
66
viewState . onSearchRegExpStateChange ( ( ) => {
62
67
this . setNeedsDisplay ( ) ;
63
68
} ) ;
@@ -166,11 +171,20 @@ export class ComponentMeasuresView extends View {
166
171
}
167
172
}
168
173
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 ) {
174
188
context . fillStyle = COLORS . SEARCH_RESULT_FILL ;
175
189
}
176
190
@@ -198,6 +212,12 @@ export class ComponentMeasuresView extends View {
198
212
visibleArea,
199
213
} = this ;
200
214
215
+ const searchRegExp = this . _viewState . searchRegExp ;
216
+ if ( this . _cachedSearchRegExp !== searchRegExp ) {
217
+ this . _cachedSearchMatches = new Map ( ) ;
218
+ this . _cachedSearchRegExp = searchRegExp ;
219
+ }
220
+
201
221
context . fillStyle = COLORS . BACKGROUND ;
202
222
context . fillRect (
203
223
visibleArea . origin . x ,
0 commit comments