[Pkg-javascript-commits] [sockjs-client] 341/350: Optimize arguments usage

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:04:37 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit 0e6dca9ee134746b47db27c6291c934f2d2582c6
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Sat Apr 30 14:03:42 2016 -0700

    Optimize arguments usage
    
    Fixes #263
---
 lib/event/emitter.js     | 10 ++++++++--
 lib/event/eventtarget.js |  6 ++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/lib/event/emitter.js b/lib/event/emitter.js
index 15d6c28..798459d 100644
--- a/lib/event/emitter.js
+++ b/lib/event/emitter.js
@@ -34,12 +34,18 @@ EventEmitter.prototype.once = function(type, listener) {
   this.on(type, g);
 };
 
-EventEmitter.prototype.emit = function(type) {
+EventEmitter.prototype.emit = function() {
+  var type = arguments[0];
   var listeners = this._listeners[type];
   if (!listeners) {
     return;
   }
-  var args = Array.prototype.slice.call(arguments, 1);
+  // equivalent of Array.prototype.slice.call(arguments, 1);
+  var l = arguments.length;
+  var args = new Array(l - 1);
+  for (var ai = 1; ai < l; ai++) {
+    args[ai - 1] = arguments[ai];
+  }
   for (var i = 0; i < listeners.length; i++) {
     listeners[i].apply(this, args);
   }
diff --git a/lib/event/eventtarget.js b/lib/event/eventtarget.js
index 3edec76..7bd81f3 100644
--- a/lib/event/eventtarget.js
+++ b/lib/event/eventtarget.js
@@ -38,9 +38,11 @@ EventTarget.prototype.removeEventListener = function(eventType, listener) {
   }
 };
 
-EventTarget.prototype.dispatchEvent = function(event) {
+EventTarget.prototype.dispatchEvent = function() {
+  var event = arguments[0];
   var t = event.type;
-  var args = Array.prototype.slice.call(arguments, 0);
+  // equivalent of Array.prototype.slice.call(arguments, 0);
+  var args = arguments.length === 1 ? [event] : Array.apply(null, arguments);
   // TODO: This doesn't match the real behavior; per spec, onfoo get
   // their place in line from the /first/ time they're set from
   // non-null. Although WebKit bumps it to the end every time it's

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list