From 33274ce400d66a17b9d60c6a298fd255a50c6e3b Mon Sep 17 00:00:00 2001 From: Roderick Hsiao Date: Tue, 31 May 2016 14:15:01 -0700 Subject: [PATCH] Micro perf enhancement (#49) --- lib/cloneDeep.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/cloneDeep.js b/lib/cloneDeep.js index 90a0299..e09e979 100644 --- a/lib/cloneDeep.js +++ b/lib/cloneDeep.js @@ -1,17 +1,15 @@ +var isA = require('./isA'); + module.exports = function cloneDeep(o) { - var newO, - i; + var newO; - if (typeof o !== 'object') { - return o; - } - if (!o) { + if (!o || typeof o !== 'object') { return o; } - if ('[object Array]' === Object.prototype.toString.apply(o)) { + if (isA(o, Array)) { newO = []; - for (i = 0; i < o.length; i += 1) { + for (var i = 0, j = o.length; i < j; i += 1) { newO[i] = cloneDeep(o[i]); } return newO;