8000 perf(copy): use ES6 Map to track source/destination objects by jbedard · Pull Request #13209 · angular/angular.js · GitHub
[go: up one dir, main page]

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

perf(copy): use ES6 Map to track source/destination objects #13209

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor(copy): avoid creating source/dest Map for simple copies
  • Loading branch information
jbedard committed Aug 28, 2016
commit 5606fe88ea67166e795b6821b314b2ee74c9d9cb
19 changes: 8 additions & 11 deletions src/Angular.js
Original file line number Diff line n 8000 umber Diff line change
Expand Up @@ -849,7 +849,7 @@ var ES6Map = isFunction(window.Map) && toString.call(window.Map.prototype) === '
</example>
*/
function copy(source, destination) {
var stack = new ES6Map();
var stack;

if (destination) {
if (isTypedArray(destination) || isArrayBuffer(destination)) {
Expand All @@ -870,13 +870,14 @@ function copy(source, destination) {
});
}

stack.set(source, destination);
return copyRecurse(source, destination);
}

return copyElement(source);

function copyRecurse(source, destination) {
(stack || (stack = new ES6Map())).set(source, destination);

var h = destination.$$hashKey;
var key;
if (isArray(source)) {
Expand Down Expand Up @@ -914,7 +915,7 @@ function copy(source, destination) {
}

// Already copied values
var existingCopy = stack.get(source);
var existingCopy = stack && stack.get(source);
if (existingCopy) {
return existingCopy;
}
Expand All @@ -924,19 +925,15 @@ function copy(source, destination) {
'Can\'t copy! Making copies of Window or Scope instances is not supported.');
}

var needsRecurse = false;
var destination = copyType(source);

if (destination === undefined) {
destination = isArray(source) ? [] : Object.create(getPrototypeOf(source));
needsRecurse = true;
destination = copyRecurse(source, isArray(source) ? [] : Object.create(getPrototypeOf(source)));
} else if (stack) {
stack.set(source, destination);
}

stack.set(source, destination);

return needsRecurse
? copyRecurse(source, destination)
: destination;
return destination;
}

function copyType(source) {
Expand Down
0