perf: Use for loops while cloning classes

This commit is contained in:
Daniel Tschinder 2019-01-16 19:35:07 -08:00
parent f216975378
commit f12905b531
2 changed files with 12 additions and 7 deletions

View File

@ -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;
} }
} }

View File

@ -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;
} }
} }