summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 19:10:30 -0400
committerNathan Dinsmore <nathan@users.noreply.github.com>2015-06-17 19:10:30 -0400
commit81b9245d25cc7a3027f21fe13bcb653a7a552c09 (patch)
treebbe8deeb05da105ff3507a8bc4ebfe18ab66f47a
parent1f52f4f1522c4bc7c24fb19ba66aeaff3bf15b64 (diff)
downloadsnap-81b9245d25cc7a3027f21fe13bcb653a7a552c09.tar.gz
snap-81b9245d25cc7a3027f21fe13bcb653a7a552c09.zip
Optimize copy()
1356.2 ms before => 73.3 ms after (on a large block stack)
-rw-r--r--morphic.js14
1 files changed, 6 insertions, 8 deletions
diff --git a/morphic.js b/morphic.js
index 737e944..013660e 100644
--- a/morphic.js
+++ b/morphic.js
@@ -1266,18 +1266,16 @@ function copy(target) {
}
if (target instanceof target.constructor &&
target.constructor !== Object) {
- c = clone(target.constructor.prototype);
- for (property in target) {
- if (Object.prototype.hasOwnProperty.call(target, property)) {
- c[property] = target[property];
- }
+ c = Object.create(target.constructor.prototype);
+ var keys = Object.keys(target);
+ for (var l = keys.length, i = 0; i < l; i++) {
+ property = keys[i];
+ c[property] = target[property];
}
} else {
c = {};
for (property in target) {
- if (!c[property]) {
- c[property] = target[property];
- }
+ c[property] = target[property];
}
}
return c;