
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
15 lines
222 B
TypeScript
15 lines
222 B
TypeScript
import { Injectable } from '@angular/core';
|
|
|
|
@Injectable()
|
|
export class MessageService {
|
|
messages: string[] = [];
|
|
|
|
add(message: string) {
|
|
this.messages.push(message);
|
|
}
|
|
|
|
clear() {
|
|
this.messages = [];
|
|
}
|
|
}
|