perf: Use for loops while cloning classes
This commit is contained in:
parent
f216975378
commit
f12905b531
@ -29,8 +29,10 @@ class Node implements NodeBase {
|
|||||||
|
|
||||||
__clone(): this {
|
__clone(): this {
|
||||||
// $FlowIgnore
|
// $FlowIgnore
|
||||||
const node2: any = new Node();
|
const newNode: any = new Node();
|
||||||
Object.keys(this).forEach(key => {
|
const keys = Object.keys(this);
|
||||||
|
for (let i = 0, length = keys.length; i < length; i++) {
|
||||||
|
const key = keys[i];
|
||||||
// Do not clone comments that are already attached to the node
|
// Do not clone comments that are already attached to the node
|
||||||
if (
|
if (
|
||||||
key !== "leadingComments" &&
|
key !== "leadingComments" &&
|
||||||
@ -38,11 +40,11 @@ class Node implements NodeBase {
|
|||||||
key !== "innerComments"
|
key !== "innerComments"
|
||||||
) {
|
) {
|
||||||
// $FlowIgnore
|
// $FlowIgnore
|
||||||
node2[key] = this[key];
|
newNode[key] = this[key];
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
return node2;
|
return newNode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -178,7 +178,9 @@ export default class State {
|
|||||||
|
|
||||||
clone(skipArrays?: boolean): State {
|
clone(skipArrays?: boolean): State {
|
||||||
const state = new State();
|
const state = new State();
|
||||||
Object.keys(this).forEach(key => {
|
const keys = Object.keys(this);
|
||||||
|
for (let i = 0, length = keys.length; i < length; i++) {
|
||||||
|
const key = keys[i];
|
||||||
// $FlowIgnore
|
// $FlowIgnore
|
||||||
let val = this[key];
|
let val = this[key];
|
||||||
|
|
||||||
@ -188,7 +190,8 @@ export default class State {
|
|||||||
|
|
||||||
// $FlowIgnore
|
// $FlowIgnore
|
||||||
state[key] = val;
|
state[key] = val;
|
||||||
});
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user