You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-09 00:22:08 +03:00
some microbenchmark updates, slight speed improvement
This commit is contained in:
@@ -24,6 +24,17 @@ util.inherits(FasterReplyParser, events.EventEmitter);
|
|||||||
|
|
||||||
exports.Parser = FasterReplyParser;
|
exports.Parser = FasterReplyParser;
|
||||||
|
|
||||||
|
// Buffer.toString() is quite slow for small strings
|
||||||
|
function small_toString(buf, start, end) {
|
||||||
|
var tmp = "", i;
|
||||||
|
|
||||||
|
for (i = start; i < end; i++) {
|
||||||
|
tmp += String.fromCharCode(buf[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
FasterReplyParser.prototype._parseResult = function (type) {
|
FasterReplyParser.prototype._parseResult = function (type) {
|
||||||
var start, end, offset, packetHeader;
|
var start, end, offset, packetHeader;
|
||||||
|
|
||||||
@@ -37,9 +48,13 @@ FasterReplyParser.prototype._parseResult = function (type) {
|
|||||||
|
|
||||||
if (this.options.return_buffers) {
|
if (this.options.return_buffers) {
|
||||||
return this._buffer.slice(start, end);
|
return this._buffer.slice(start, end);
|
||||||
|
} else {
|
||||||
|
if (end - start < 65536) { // completely arbitrary
|
||||||
|
return small_toString(this._buffer, start, end);
|
||||||
} else {
|
} else {
|
||||||
return this._buffer.toString(this._encoding, start, end);
|
return this._buffer.toString(this._encoding, start, end);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (type === 58) { // :
|
} else if (type === 58) { // :
|
||||||
// up to the delimiter
|
// up to the delimiter
|
||||||
end = this._packetEndOffset() - 1;
|
end = this._packetEndOffset() - 1;
|
||||||
@@ -49,7 +64,7 @@ FasterReplyParser.prototype._parseResult = function (type) {
|
|||||||
this._offset = end + 2;
|
this._offset = end + 2;
|
||||||
|
|
||||||
// return the coerced numeric value
|
// return the coerced numeric value
|
||||||
return +this._buffer.toString(this._encoding, start, end);
|
return +small_toString(this._buffer, start, end);
|
||||||
} else if (type === 36) { // $
|
} else if (type === 36) { // $
|
||||||
// set a rewind point, as the packet could be larger than the
|
// set a rewind point, as the packet could be larger than the
|
||||||
// buffer in memory
|
// buffer in memory
|
||||||
@@ -185,7 +200,7 @@ FasterReplyParser.prototype.append = function(newBuffer) {
|
|||||||
|
|
||||||
FasterReplyParser.prototype.parseHeader = function () {
|
FasterReplyParser.prototype.parseHeader = function () {
|
||||||
var end = this._packetEndOffset(),
|
var end = this._packetEndOffset(),
|
||||||
value = this._buffer.toString(this._encoding, this._offset, end - 1);
|
value = small_toString(this._buffer, this._offset, end - 1);
|
||||||
|
|
||||||
this._offset = end + 1;
|
this._offset = end + 1;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user