docs(aio): Clearing array with [] (#20369) (#20395)

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:
Shavi Pathania 2017-11-13 21:13:37 +05:30 committed by Miško Hevery
parent 717ac5ac4d
commit 0fedb57cb0
11 changed files with 11 additions and 11 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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

View File

@ -68,7 +68,7 @@ export class DoCheckComponent implements DoCheck {
reset() {
this.changeDetected = true;
this.changeLog.length = 0;
this.changeLog = [];
}
}

View File

@ -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(() => { }); }

View File

@ -43,7 +43,7 @@ export class OnChangesComponent implements OnChanges {
}
// #enddocregion ng-on-changes
reset() { this.changeLog.length = 0; }
reset() { this.changeLog = []; }
}
/***************************************/

View File

@ -34,7 +34,7 @@ export class SpyParentComponent {
}
reset() {
this.logger.log('-- reset --');
this.heroes.length = 0;
this.heroes = [];
this.logger.tick();
}
}

View File

@ -9,6 +9,6 @@ export class MessageService {
}
clear() {
this.messages.length = 0;
this.messages = [];
}
}

View File

@ -9,6 +9,6 @@ export class MessageService {
}
clear() {
this.messages.length = 0;
this.messages = [];
}
}

View File

@ -9,6 +9,6 @@ export class MessageService {
}
clear() {
this.messages.length = 0;
this.messages = [];
}
}

View File

@ -9,6 +9,6 @@ export class MessageService {
}
clear() {
this.messages.length = 0;
this.messages = [];
}
}