mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor(core): simplify concatStringsWithSpace (#59820)
The new version of the function is smaller, eliminating extra bytes. The refactor improves both code size and readability while optimizing the implementation. Benchmark results for the old and new implementations are as follows: ``` concatStringsWithSpace_old x 149,225,311 ops/sec ±8.54% (50 runs sampled) concatStringsWithSpace_new x 160,206,834 ops/sec ±5.72% (54 runs sampled) ``` Thus, the new implementation is both smaller and faster. PR Close #59820
This commit is contained in:
parent
9f092142d9
commit
20f5dc5103
1 changed files with 3 additions and 7 deletions
|
|
@ -46,13 +46,9 @@ export function stringify(token: any): string {
|
|||
* @returns concatenated string.
|
||||
*/
|
||||
export function concatStringsWithSpace(before: string | null, after: string | null): string {
|
||||
return before == null || before === ''
|
||||
? after === null
|
||||
? ''
|
||||
: after
|
||||
: after == null || after === ''
|
||||
? before
|
||||
: before + ' ' + after;
|
||||
if (!before) return after || '';
|
||||
if (!after) return before;
|
||||
return `${before} ${after}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue