diff --git a/lib/events.js b/lib/events.js index 02e7ac951463c0..6bd2a77db26907 100644 --- a/lib/events.js +++ b/lib/events.js @@ -384,7 +384,7 @@ EventEmitter.prototype.listeners = function listeners(type) { else if (typeof evlistener === 'function') ret = [evlistener]; else - ret = arrayClone(evlistener); + ret = arrayClone(evlistener, evlistener.length); } return ret; @@ -413,16 +413,9 @@ function spliceOne(list, index) { list.pop(); } -function arrayClone(arr, len) { - var ret; - if (len === undefined) - len = arr.length; - if (len >= 50) - ret = arr.slice(); - else { - ret = new Array(len); - for (var i = 0; i < len; i += 1) - ret[i] = arr[i]; - } - return ret; +function arrayClone(arr, i) { + var copy = new Array(i); + while (i--) + copy[i] = arr[i]; + return copy; }