Skip to content

Commit adbdc9d

Browse files
committed
improved performance of the tree control
1 parent 671ed98 commit adbdc9d

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

angular-tree-control.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,31 @@
4646
return !node[$scope.options.nodeChildren] || node[$scope.options.nodeChildren].length === 0;
4747
}
4848

49+
function shallowCopy(src, dst) {
50+
if (angular.isArray(src)) {
51+
dst = dst || [];
52+
53+
for ( var i = 0; i < src.length; i++) {
54+
dst[i] = src[i];
55+
}
56+
} else if (angular.isObject(src)) {
57+
dst = dst || {};
58+
59+
for (var key in src) {
60+
if (hasOwnProperty.call(src, key) && !(key.charAt(0) === '$' && key.charAt(1) === '$')) {
61+
dst[key] = src[key];
62+
}
63+
}
64+
}
65+
66+
return dst || src;
67+
}
4968
function defaultEquality(a, b) {
5069
if (a === undefined || b === undefined)
5170
return false;
52-
a = angular.copy(a);
71+
a = shallowCopy(a);
5372
a[$scope.options.nodeChildren] = [];
54-
b = angular.copy(b);
73+
b = shallowCopy(b);
5574
b[$scope.options.nodeChildren] = [];
5675
return angular.equals(a, b);
5776
}

0 commit comments

Comments
 (0)