Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 4db3ac1

Browse files
jbedardgkalpak
authored andcommitted
refactor(copy): avoid creating source/dest Map for simple copies
1 parent 95f9179 commit 4db3ac1

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/Angular.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ var ES6Map = isFunction(window.Map) && toString.call(window.Map.prototype) === '
855855
</example>
856856
*/
857857
function copy(source, destination) {
858-
var stack = new ES6Map();
858+
var stack;
859859

860860
if (destination) {
861861
if (isTypedArray(destination) || isArrayBuffer(destination)) {
@@ -876,13 +876,14 @@ function copy(source, destination) {
876876
});
877877
}
878878

879-
stack.set(source, destination);
880879
return copyRecurse(source, destination);
881880
}
882881

883882
return copyElement(source);
884883

885884
function copyRecurse(source, destination) {
885+
(stack || (stack = new ES6Map())).set(source, destination);
886+
886887
var h = destination.$$hashKey;
887888
var key;
888889
if (isArray(source)) {
@@ -920,7 +921,7 @@ function copy(source, destination) {
920921
}
921922

922923
// Already copied values
923-
var existingCopy = stack.get(source);
924+
var existingCopy = stack && stack.get(source);
924925
if (existingCopy) {
925926
return existingCopy;
926927
}
@@ -930,19 +931,15 @@ function copy(source, destination) {
930931
'Can\'t copy! Making copies of Window or Scope instances is not supported.');
931932
}
932933

933-
var needsRecurse = false;
934934
var destination = copyType(source);
935935

936936
if (destination === undefined) {
937-
destination = isArray(source) ? [] : Object.create(getPrototypeOf(source));
938-
needsRecurse = true;
937+
destination = copyRecurse(source, isArray(source) ? [] : Object.create(getPrototypeOf(source)));
938+
} else if (stack) {
939+
stack.set(source, destination);
939940
}
940941

941-
stack.set(source, destination);
942-
943-
return needsRecurse
944-
? copyRecurse(source, destination)
945-
: destination;
942+
return destination;
946943
}
947944

948945
function copyType(source) {

0 commit comments

Comments
 (0)