Skip to content

Commit c46d448

Browse files
billouboqdarrachequesne
authored andcommitted
[perf] micro-optimisations (socketio#2793)
1 parent d821900 commit c46d448

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/socket.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,14 @@ Socket.prototype.emit = function(ev){
141141
emit.apply(this, arguments);
142142
} else {
143143
var args = Array.prototype.slice.call(arguments);
144-
var packet = {};
145-
packet.type = hasBin(args) ? parser.BINARY_EVENT : parser.EVENT;
146-
packet.data = args;
144+
var packet = {
145+
type: hasBin(args) ? parser.BINARY_EVENT : parser.EVENT,
146+
data: args
147+
};
147148
var flags = this.flags || {};
148149

149150
// access last argument to see if it's an ACK callback
150-
if ('function' == typeof args[args.length - 1]) {
151+
if (typeof args[args.length - 1] === 'function') {
151152
if (this._rooms || flags.broadcast) {
152153
throw new Error('Callbacks are not supported when broadcasting');
153154
}
@@ -495,15 +496,16 @@ Socket.prototype.compress = function(compress){
495496
Socket.prototype.dispatch = function(event){
496497
debug('dispatching an event %j', event);
497498
var self = this;
498-
this.run(event, function(err){
499+
function dispatchSocket(err) {
499500
process.nextTick(function(){
500501
if (err) {
501502
return self.error(err.data || err.message);
502503
}
503504
emit.apply(self, event);
504505
});
505-
});
506-
}
506+
}
507+
this.run(event, dispatchSocket);
508+
};
507509

508510
/**
509511
* Sets up socket middleware.

0 commit comments

Comments
 (0)