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;
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('.');
}
}

View File

@ -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('.');
}
}

View File

@ -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('.');
}
}