Skip to content
Browse files

Speed up generated prepared functions

Simple benchmarks show ~19% improvement
  • Loading branch information...
1 parent a8b12f6 commit 2b571fdf4a4d57b320cb84e13ef08f6306b98888 @mscdex committed Oct 19, 2012
Showing with 8 additions and 7 deletions.
  1. +8 −7 lib/Client.js
View
15 lib/Client.js
@@ -230,16 +230,17 @@ Client.prototype.prepare = function(query) {
parts.push(query.substring(curpos));
fn = function(values) {
- var ret = '', j, len, str;
+ var ret = '', j, len, val;
for (j=0,len=tokens.length; j<len; ++j) {
- if (Buffer.isBuffer(values[tokens[j]]))
- str = values[tokens[j]].toString('utf8');
- else
- str = values[tokens[j]] + '';
ret += parts[j];
- if (values[tokens[j]] !== null) {
+ val = values[tokens[j]];
+ if (Buffer.isBuffer(val)) {
ret += "'";
- ret += addon.escape(str);
+ ret += addon.escape(val.toString('utf8'));
+ ret += "'";
+ } else if (val !== null) {
+ ret += "'";
+ ret += addon.escape(val + '');
ret += "'";
} else
ret += 'NULL';

0 comments on commit 2b571fd

Please sign in to comment.
Something went wrong with that request. Please try again.