Skip to content

Commit 32cf725

Browse files
committed
Using created function for slightly better performance.
1 parent 86074dd commit 32cf725

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

lib/connection.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function Connection(stream, server) {
2020
this.stream = stream;
2121
}
2222

23+
this.generate = generate;
2324
this.buffer = null;
2425
this.packet = {};
2526
this.skip = false;
@@ -116,14 +117,14 @@ Connection.prototype.parse = function() {
116117
for (var k in protocol.types) {
117118
var v = protocol.types[k];
118119

119-
Connection.prototype[v] = function(type) {
120-
return function(opts) {
121-
var p = generate[type](opts);
122-
if (p instanceof Error) {
123-
this.emit('error', p)
124-
} else {
125-
this.stream.write(p);
126-
}
127-
}
128-
}(v);
120+
var fun = "" +
121+
" var p = this.generate." + v +"(arguments[0]); " +
122+
" if (p instanceof Error) { " +
123+
" this.emit('error', p) " +
124+
" } else { " +
125+
" this.stream.write(p); " +
126+
" } "
127+
" } ";
128+
129+
Connection.prototype[v] = new Function(fun);
129130
}

0 commit comments

Comments
 (0)