Permalink
Browse files

Do not use bind in read and write for better performance.

  • Loading branch information...
1 parent 07ee381 commit 4df4fc92884bd3bd8816b638a8ae5589726f22d8 @mcollina mcollina committed Sep 19, 2013
Showing with 12 additions and 6 deletions.
  1. +6 −3 read.js
  2. +6 −3 write.js
View
@@ -1,15 +1,18 @@
var proto = {}
, rex = /read.+/
- , fn
+ , buildFn
-fn = function() {
+buildFn = function(key) {
+ var code = '' +
+ 'return buf.' + key + '(' + ['a', 'b', 'c'].join(',' ) + ')'
+ return new Function(['buf', 'a', 'b', 'c'], code)
}
module.exports = proto
for(var key in Buffer.prototype) {
if(rex.test(key)) {
- proto[key] = fn.call.bind(Buffer.prototype[key])
+ proto[key] = buildFn(key)
}
}
View
@@ -2,16 +2,19 @@ var Buffer = require('buffer').Buffer
var proto = {}
, rex = /write.+/
- , fn
+ , buildFn
-fn = function() {
+buildFn = function(key) {
+ var code = '' +
+ 'return buf.' + key + '(' + ['a', 'b', 'c'].join(',' ) + ')'
+ return new Function(['buf', 'a', 'b', 'c'], code)
}
module.exports = proto
for(var key in Buffer.prototype) {
if(rex.test(key)) {
- proto[key] = fn.call.bind(Buffer.prototype[key])
+ proto[key] = buildFn(key)
}
}

0 comments on commit 4df4fc9

Please sign in to comment.