diff --git a/lib/parser/javascript.js b/lib/parser/javascript.js index f58a46d15e..d5755e9959 100644 --- a/lib/parser/javascript.js +++ b/lib/parser/javascript.js @@ -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; } }; diff --git a/package.json b/package.json index 8c9e1780b6..d69ecab363 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { "name" : "redis", - "version" : "0.4.1", + "version" : "0.4.2", "description" : "Redis client library", "author": "Matt Ranney ", "contributors": [