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:
parent
562a782114
commit
744bd2b64f
|
@ -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('.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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('.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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('.');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue