From 744bd2b64f6dd2e7b25cbc0bedd03abc3f59d264 Mon Sep 17 00:00:00 2001 From: Julien Marcou Date: Sat, 20 Mar 2021 14:20:40 +0100 Subject: [PATCH] refactor(core): optimize calls to `split` and `slice` while computing version parts (#41208) Reduce the number of calls made to `split` and `slice` while computing version parts by deconstructing the result. PR Close #41208 --- packages/animations/src/version.ts | 8 ++++---- packages/compiler/src/util.ts | 8 ++++---- packages/core/src/version.ts | 7 ++++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/animations/src/version.ts b/packages/animations/src/version.ts index 3eca0eb3c8..ce0a0cd10e 100644 --- a/packages/animations/src/version.ts +++ b/packages/animations/src/version.ts @@ -23,10 +23,10 @@ export class Version { public readonly patch: string; constructor(public full: string) { - const splits = full.split('.'); - this.major = splits[0]; - this.minor = splits[1]; - this.patch = splits.slice(2).join('.'); + const [major, minor, ...rest] = full.split('.'); + this.major = major; + this.minor = minor; + this.patch = rest.join('.'); } } diff --git a/packages/compiler/src/util.ts b/packages/compiler/src/util.ts index 8c62653f09..57fa10fae9 100644 --- a/packages/compiler/src/util.ts +++ b/packages/compiler/src/util.ts @@ -236,10 +236,10 @@ export class Version { public readonly patch: string; constructor(public full: string) { - const splits = full.split('.'); - this.major = splits[0]; - this.minor = splits[1]; - this.patch = splits.slice(2).join('.'); + const [major, minor, ...rest] = full.split('.'); + this.major = major; + this.minor = minor; + this.patch = rest.join('.'); } } diff --git a/packages/core/src/version.ts b/packages/core/src/version.ts index 71a5cb8878..aea151d90c 100644 --- a/packages/core/src/version.ts +++ b/packages/core/src/version.ts @@ -17,9 +17,10 @@ export class Version { public readonly patch: string; constructor(public full: string) { - this.major = full.split('.')[0]; - this.minor = full.split('.')[1]; - this.patch = full.split('.').slice(2).join('.'); + const [major, minor, ...rest] = full.split('.'); + this.major = major; + this.minor = minor; + this.patch = rest.join('.'); } }