@@ -83,6 +83,7 @@ export default class Store extends EventEmitter<{|
8383 // Computed whenever _errorsAndWarnings Map changes.
8484 _cachedErrorCount : number = 0 ;
8585 _cachedWarningCount: number = 0 ;
86+ _cachedErrorAndWarningTuples: Array < { | id : number , index : number | } > = [ ] ;
8687
8788 // Should new nodes be collapsed by default when added to the tree?
8889 _collapseNodesByDefault: boolean = true ;
@@ -483,27 +484,7 @@ export default class Store extends EventEmitter<{|
483484
484485 // Returns a tuple of [id, index]
485486 getElementsWithErrorsAndWarnings ( ) : Array < { | id : number , index : number | } > {
486- const sortedArray : Array < { | id : number , index : number | } > = [ ] ;
487-
488- this . _errorsAndWarnings . forEach ( ( _ , id ) => {
489- const index = this . getIndexOfElementID ( id ) ;
490- if ( index !== null ) {
491- let low = 0 ;
492- let high = sortedArray . length ;
493- while ( low < high ) {
494- const mid = ( low + high ) >> 1 ;
495- if ( sortedArray [ mid ] . index > index ) {
496- high = mid ;
497- } else {
498- low = mid + 1 ;
499- }
500- }
501-
502- sortedArray . splice ( low , 0 , { id, index} ) ;
503- }
504- } ) ;
505-
506- return sortedArray ;
487+ return this . _cachedErrorAndWarningTuples ;
507488 }
508489
509490 getErrorAndWarningCountForElementID (
@@ -1123,6 +1104,28 @@ export default class Store extends EventEmitter<{|
11231104
11241105 this . _cachedErrorCount = errorCount ;
11251106 this . _cachedWarningCount = warningCount ;
1107+
1108+ const errorAndWarningTuples : Array < { | id : number , index : number | } > = [ ] ;
1109+
1110+ this . _errorsAndWarnings . forEach ( ( _ , id ) => {
1111+ const index = this . getIndexOfElementID ( id ) ;
1112+ if ( index !== null ) {
1113+ let low = 0 ;
1114+ let high = errorAndWarningTuples . length ;
1115+ while ( low < high ) {
1116+ const mid = ( low + high ) >> 1 ;
1117+ if ( errorAndWarningTuples [ mid ] . index > index ) {
1118+ high = mid ;
1119+ } else {
1120+ low = mid + 1 ;
1121+ }
1122+ }
1123+
1124+ errorAndWarningTuples . splice ( low , 0 , { id, index} ) ;
1125+ }
1126+ } ) ;
1127+
1128+ this . _cachedErrorAndWarningTuples = errorAndWarningTuples ;
11261129 }
11271130
11281131 if ( haveRootsChanged ) {
0 commit comments