You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-07 13:22:56 +03:00
Allocate new Arrays with known size instead of dynamically growing them.
This commit is contained in:
@@ -43,6 +43,7 @@ RedisReplyParser.prototype.reset = function () {
|
||||
|
||||
this.multi_bulk_length = 0;
|
||||
this.multi_bulk_replies = null;
|
||||
this.multi_bulk_pos = 0;
|
||||
this.multi_bulk_nested_length = 0;
|
||||
this.multi_bulk_nested_replies = null;
|
||||
};
|
||||
@@ -136,16 +137,20 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
|
||||
if (this.multi_bulk_length) { // nested multi-bulk
|
||||
this.multi_bulk_nested_length = this.multi_bulk_length;
|
||||
this.multi_bulk_nested_replies = this.multi_bulk_replies;
|
||||
this.multi_bulk_nested_pos = this.multi_bulk_pos;
|
||||
}
|
||||
this.multi_bulk_length = +this.tmp_string;
|
||||
this.multi_bulk_replies = [];
|
||||
this.multi_bulk_pos = 0;
|
||||
this.state = "type";
|
||||
if (this.multi_bulk_length < 0) {
|
||||
this.send_reply(null);
|
||||
this.multi_bulk_length = 0;
|
||||
} else if (this.multi_bulk_length === 0) {
|
||||
this.multi_bulk_pos = 0;
|
||||
this.multi_bulk_replies = null;
|
||||
this.send_reply([]);
|
||||
} else {
|
||||
this.multi_bulk_replies = new Array(this.multi_bulk_length);
|
||||
}
|
||||
} else {
|
||||
this.parser_error(new Error("didn't see LF after NL reading multi bulk count"));
|
||||
@@ -265,8 +270,9 @@ RedisReplyParser.prototype.send_reply = function (reply) {
|
||||
|
||||
RedisReplyParser.prototype.add_multi_bulk_reply = function (reply) {
|
||||
if (this.multi_bulk_replies) {
|
||||
this.multi_bulk_replies.push(reply);
|
||||
if (this.multi_bulk_replies.length < this.multi_bulk_length) {
|
||||
this.multi_bulk_replies[this.multi_bulk_pos] = reply;
|
||||
this.multi_bulk_pos += 1;
|
||||
if (this.multi_bulk_pos < this.multi_bulk_length) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -274,17 +280,23 @@ RedisReplyParser.prototype.add_multi_bulk_reply = function (reply) {
|
||||
}
|
||||
|
||||
if (this.multi_bulk_nested_length > 0) {
|
||||
this.multi_bulk_nested_replies.push(this.multi_bulk_replies);
|
||||
this.multi_bulk_nested_replies[this.multi_bulk_nested_pos] = this.multi_bulk_replies;
|
||||
this.multi_bulk_nested_pos += 1;
|
||||
|
||||
this.multi_bulk_length = 0;
|
||||
delete this.multi_bulk_replies;
|
||||
if (this.multi_bulk_nested_length === this.multi_bulk_nested_replies.length) {
|
||||
this.multi_bulk_replies = null;
|
||||
this.multi_bulk_pos = 0;
|
||||
|
||||
if (this.multi_bulk_nested_length === this.multi_bulk_nested_pos) {
|
||||
this.emit("reply", this.multi_bulk_nested_replies);
|
||||
this.multi_bulk_nested_length = 0;
|
||||
this.multi_bulk_nested_pos = 0;
|
||||
this.multi_bulk_nested_replies = null;
|
||||
}
|
||||
} else {
|
||||
this.emit("reply", this.multi_bulk_replies);
|
||||
this.multi_bulk_length = 0;
|
||||
this.multi_bulk_replies = null;
|
||||
this.multi_bulk_pos = 0;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user