Skip to content

Commit ff2c15d

Browse files
tabonedarrachequesne
authored andcommitted
[perf] Minor code optimizations (#2219)
1 parent a483658 commit ff2c15d

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

lib/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,16 +382,17 @@ var emitterMethods = Object.keys(Emitter.prototype).filter(function(key){
382382

383383
emitterMethods.concat(['to', 'in', 'use', 'send', 'write', 'clients', 'compress']).forEach(function(fn){
384384
Server.prototype[fn] = function(){
385-
var nsp = this.sockets[fn];
386-
return nsp.apply(this.sockets, arguments);
385+
return this.sockets[fn].apply(this.sockets, arguments);
387386
};
388387
});
389388

390389
Namespace.flags.forEach(function(flag){
391-
Server.prototype.__defineGetter__(flag, function(){
392-
this.sockets.flags = this.sockets.flags || {};
393-
this.sockets.flags[flag] = true;
394-
return this;
390+
Object.defineProperty(Server.prototype, flag, {
391+
get: function() {
392+
this.sockets.flags = this.sockets.flags || {};
393+
this.sockets.flags[flag] = true;
394+
return this;
395+
}
395396
});
396397
});
397398

lib/namespace.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ Namespace.prototype.__proto__ = Emitter.prototype;
6969
*/
7070

7171
exports.flags.forEach(function(flag){
72-
Namespace.prototype.__defineGetter__(flag, function(){
73-
this.flags = this.flags || {};
74-
this.flags[flag] = true;
75-
return this;
72+
Object.defineProperty(Namespace.prototype, flag, {
73+
get: function() {
74+
this.flags = this.flags || {};
75+
this.flags[flag] = true;
76+
return this;
77+
}
7678
});
7779
});
7880

@@ -137,7 +139,7 @@ Namespace.prototype.run = function(socket, fn){
137139
*/
138140

139141
Namespace.prototype.to =
140-
Namespace.prototype['in'] = function(name){
142+
Namespace.prototype.in = function(name){
141143
this.rooms = this.rooms || [];
142144
if (!~this.rooms.indexOf(name)) this.rooms.push(name);
143145
return this;

lib/socket.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ Socket.prototype.__proto__ = Emitter.prototype;
8383
*/
8484

8585
flags.forEach(function(flag){
86-
Socket.prototype.__defineGetter__(flag, function(){
87-
this.flags = this.flags || {};
88-
this.flags[flag] = true;
89-
return this;
86+
Object.defineProperty(Socket.prototype, flag, {
87+
get: function() {
88+
this.flags = this.flags || {};
89+
this.flags[flag] = true;
90+
return this;
91+
}
9092
});
9193
});
9294

@@ -96,8 +98,10 @@ flags.forEach(function(flag){
9698
* @api public
9799
*/
98100

99-
Socket.prototype.__defineGetter__('request', function(){
100-
return this.conn.request;
101+
Object.defineProperty(Socket.prototype, 'request', {
102+
get: function() {
103+
return this.conn.request;
104+
}
101105
});
102106

103107
/**

0 commit comments

Comments
 (0)