Clearing array with setting length to 0 replaced with [] for being short and marginally efficient. For reference: [] is turned into a sequence of around 15 machine instructions on x64 (if bump pointer allocation succeeds), whereas a.length=0 is a C++ runtime function call, which requires 10-100x as many instructions. Benedikt Meurer PR Close #20395
This commit is contained in:
parent
717ac5ac4d
commit
0fedb57cb0
|
@ -108,7 +108,7 @@ export class AfterContentParentComponent {
|
|||
}
|
||||
|
||||
reset() {
|
||||
this.logs.length = 0;
|
||||
this.logs = [];
|
||||
// quickly remove and reload AfterContentComponent which recreates it
|
||||
this.show = false;
|
||||
this.logger.tick_then(() => this.show = true);
|
||||
|
|
|
@ -110,7 +110,7 @@ export class AfterViewParentComponent {
|
|||
}
|
||||
|
||||
reset() {
|
||||
this.logs.length = 0;
|
||||
this.logs = [];
|
||||
// quickly remove and reload AfterViewComponent which recreates it
|
||||
this.show = false;
|
||||
this.logger.tick_then(() => this.show = true);
|
||||
|
|
|
@ -27,7 +27,7 @@ export class MyCounterComponent implements OnChanges {
|
|||
// Empty the changeLog whenever counter goes to zero
|
||||
// hint: this is a way to respond programmatically to external value changes.
|
||||
if (this.counter === 0) {
|
||||
this.changeLog.length = 0;
|
||||
this.changeLog = [];
|
||||
}
|
||||
|
||||
// A change to `counter` is the only change we care about
|
||||
|
|
|
@ -68,7 +68,7 @@ export class DoCheckComponent implements DoCheck {
|
|||
|
||||
reset() {
|
||||
this.changeDetected = true;
|
||||
this.changeLog.length = 0;
|
||||
this.changeLog = [];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ export class LoggerService {
|
|||
}
|
||||
}
|
||||
|
||||
clear() { this.logs.length = 0; }
|
||||
clear() { this.logs = []; }
|
||||
|
||||
// schedules a view refresh to ensure display catches up
|
||||
tick() { this.tick_then(() => { }); }
|
||||
|
|
|
@ -43,7 +43,7 @@ export class OnChangesComponent implements OnChanges {
|
|||
}
|
||||
// #enddocregion ng-on-changes
|
||||
|
||||
reset() { this.changeLog.length = 0; }
|
||||
reset() { this.changeLog = []; }
|
||||
}
|
||||
|
||||
/***************************************/
|
||||
|
|
|
@ -34,7 +34,7 @@ export class SpyParentComponent {
|
|||
}
|
||||
reset() {
|
||||
this.logger.log('-- reset --');
|
||||
this.heroes.length = 0;
|
||||
this.heroes = [];
|
||||
this.logger.tick();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ export class MessageService {
|
|||
}
|
||||
|
||||
clear() {
|
||||
this.messages.length = 0;
|
||||
this.messages = [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ export class MessageService {
|
|||
}
|
||||
|
||||
clear() {
|
||||
this.messages.length = 0;
|
||||
this.messages = [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ export class MessageService {
|
|||
}
|
||||
|
||||
clear() {
|
||||
this.messages.length = 0;
|
||||
this.messages = [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,6 @@ export class MessageService {
|
|||
}
|
||||
|
||||
clear() {
|
||||
this.messages.length = 0;
|
||||
this.messages = [];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue