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:
arturovt 2025-01-29 08:23:20 +02:00 committed by Jessica Janiuk
parent 9f092142d9
commit 20f5dc5103

View file

@ -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}`;
}
/**