File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed
Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -115,8 +115,16 @@ <h3>Brief explanation</h3>
115115{
116116let filter = document . querySelector ( "#filter" ) . value ;
117117let test_names = unique ( [ ...Object . keys ( data . a . data ) , ...Object . keys ( data . b . data ) ] ) ;
118+ let isCopied = false
118119for ( let name of test_names ) {
119120if ( ! name . includes ( filter ) ) {
121+ if ( ! isCopied ) {
122+ // Copying data is very expensive
123+ // This branch ensures that we avoid copying
124+ // if there are no filters (which is the most common case)
125+ data = JSON . parse ( JSON . stringify ( DATA ) ) ; // deep copy
126+ isCopied = true
127+ }
120128delete data . a . data [ name ] ;
121129delete data . b . data [ name ] ;
122130}
@@ -331,7 +339,6 @@ <h3>Brief explanation</h3>
331339} , state ) ;
332340make_request ( "/get" , values ) . then ( function ( data ) {
333341DATA = data ;
334- data = JSON . parse ( JSON . stringify ( DATA ) ) ; // deep copy
335342populate_data ( data ) ;
336343} ) ;
337344}
@@ -350,8 +357,7 @@ <h3>Brief explanation</h3>
350357load_state ( make_data ) ;
351358
352359function rerender ( ) {
353- let data = JSON . parse ( JSON . stringify ( DATA ) ) ; // deep copy
354- populate_data ( data ) ;
360+ populate_data ( DATA ) ;
355361}
356362
357363document . querySelector ( "#filter" ) . addEventListener ( "change" , rerender ) ;
You can’t perform that action at this time.
0 commit comments