mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08: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:
@@ -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}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user