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
This commit is contained in:
Julien Marcou 2021-03-20 14:20:40 +01:00 committed by Alex Rickabaugh
parent 562a782114
commit 744bd2b64f
3 changed files with 12 additions and 11 deletions

View File

@ -23,10 +23,10 @@ export class Version {
public readonly patch: string; public readonly patch: string;
constructor(public full: string) { constructor(public full: string) {
const splits = full.split('.'); const [major, minor, ...rest] = full.split('.');
this.major = splits[0]; this.major = major;
this.minor = splits[1]; this.minor = minor;
this.patch = splits.slice(2).join('.'); this.patch = rest.join('.');
} }
} }

View File

@ -236,10 +236,10 @@ export class Version {
public readonly patch: string; public readonly patch: string;
constructor(public full: string) { constructor(public full: string) {
const splits = full.split('.'); const [major, minor, ...rest] = full.split('.');
this.major = splits[0]; this.major = major;
this.minor = splits[1]; this.minor = minor;
this.patch = splits.slice(2).join('.'); this.patch = rest.join('.');
} }
} }

View File

@ -17,9 +17,10 @@ export class Version {
public readonly patch: string; public readonly patch: string;
constructor(public full: string) { constructor(public full: string) {
this.major = full.split('.')[0]; const [major, minor, ...rest] = full.split('.');
this.minor = full.split('.')[1]; this.major = major;
this.patch = full.split('.').slice(2).join('.'); this.minor = minor;
this.patch = rest.join('.');
} }
} }