1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-09 00:22:08 +03:00

Use number literals for case labels to help V8 go faster.

This commit is contained in:
Matt Ranney
2011-11-13 18:12:28 -10:00
parent b633587b49
commit 0c8646bc61

View File

@@ -56,7 +56,8 @@ RedisReplyParser.prototype.reset = function () {
UNKNOWN_TYPE: 8, UNKNOWN_TYPE: 8,
FINAL_CR: 9, FINAL_CR: 9,
FINAL_LF: 10, FINAL_LF: 10,
MULTI_BULK_COUNT_LF: 11 MULTI_BULK_COUNT_LF: 11,
BULK_LF: 12
}; };
this.state = this.states.TYPE; this.state = this.states.TYPE;
@@ -77,7 +78,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
// console.log("execute: " + this.state + ", " + pos + "/" + incoming_buf.length + ", " + String.fromCharCode(incoming_buf[pos])); // console.log("execute: " + this.state + ", " + pos + "/" + incoming_buf.length + ", " + String.fromCharCode(incoming_buf[pos]));
switch (this.state) { switch (this.state) {
case states.TYPE: case 1: // states.TYPE
this.type = incoming_buf[pos]; this.type = incoming_buf[pos];
pos += 1; pos += 1;
@@ -109,7 +110,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
this.state = states.UNKNOWN_TYPE; this.state = states.UNKNOWN_TYPE;
} }
break; break;
case states.INTEGER_LINE: case 4: // states.INTEGER_LINE
if (incoming_buf[pos] === 13) { if (incoming_buf[pos] === 13) {
this.send_reply(+small_toString(this.return_buffer, this.return_buffer.end)); this.send_reply(+small_toString(this.return_buffer, this.return_buffer.end));
this.state = states.FINAL_LF; this.state = states.FINAL_LF;
@@ -119,7 +120,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
} }
pos += 1; pos += 1;
break; break;
case states.ERROR_LINE: case 6: // states.ERROR_LINE
if (incoming_buf[pos] === 13) { if (incoming_buf[pos] === 13) {
this.send_error(this.return_buffer.toString("ascii", 0, this.return_buffer.end)); this.send_error(this.return_buffer.toString("ascii", 0, this.return_buffer.end));
this.state = states.FINAL_LF; this.state = states.FINAL_LF;
@@ -129,7 +130,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
} }
pos += 1; pos += 1;
break; break;
case states.SINGLE_LINE: case 2: // states.SINGLE_LINE
if (incoming_buf[pos] === 13) { if (incoming_buf[pos] === 13) {
this.send_reply(this.return_string); this.send_reply(this.return_string);
this.state = states.FINAL_LF; this.state = states.FINAL_LF;
@@ -138,7 +139,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
} }
pos += 1; pos += 1;
break; break;
case states.MULTI_BULK_COUNT: case 3: // states.MULTI_BULK_COUNT
if (incoming_buf[pos] === 13) { // \r if (incoming_buf[pos] === 13) { // \r
this.state = states.MULTI_BULK_COUNT_LF; this.state = states.MULTI_BULK_COUNT_LF;
} else { } else {
@@ -146,7 +147,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
} }
pos += 1; pos += 1;
break; break;
case states.MULTI_BULK_COUNT_LF: case 11: // states.MULTI_BULK_COUNT_LF
if (incoming_buf[pos] === 10) { // \n if (incoming_buf[pos] === 10) { // \n
if (this.multi_bulk_length) { // nested multi-bulk if (this.multi_bulk_length) { // nested multi-bulk
this.multi_bulk_nested_length = this.multi_bulk_length; this.multi_bulk_nested_length = this.multi_bulk_length;
@@ -172,7 +173,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
} }
pos += 1; pos += 1;
break; break;
case states.BULK_LENGTH: case 5: // states.BULK_LENGTH
if (incoming_buf[pos] === 13) { // \r if (incoming_buf[pos] === 13) { // \r
this.state = states.BULK_LF; this.state = states.BULK_LF;
} else { } else {
@@ -180,7 +181,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
} }
pos += 1; pos += 1;
break; break;
case states.BULK_LF: case 12: // states.BULK_LF
if (incoming_buf[pos] === 10) { // \n if (incoming_buf[pos] === 10) { // \n
this.bulk_length = +this.tmp_string; this.bulk_length = +this.tmp_string;
if (this.bulk_length === -1) { if (this.bulk_length === -1) {
@@ -205,7 +206,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
} }
pos += 1; pos += 1;
break; break;
case states.BULK_DATA: case 7: // states.BULK_DATA
this.return_buffer[this.return_buffer.end] = incoming_buf[pos]; this.return_buffer[this.return_buffer.end] = incoming_buf[pos];
this.return_buffer.end += 1; this.return_buffer.end += 1;
pos += 1; pos += 1;
@@ -223,7 +224,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
this.state = states.FINAL_CR; this.state = states.FINAL_CR;
} }
break; break;
case states.FINAL_CR: case 9: // states.FINAL_CR
if (incoming_buf[pos] === 13) { // \r if (incoming_buf[pos] === 13) { // \r
this.state = states.FINAL_LF; this.state = states.FINAL_LF;
pos += 1; pos += 1;
@@ -232,7 +233,7 @@ RedisReplyParser.prototype.execute = function (incoming_buf) {
return; return;
} }
break; break;
case states.FINAL_LF: case 10: // states.FINAL_LF
if (incoming_buf[pos] === 10) { // \n if (incoming_buf[pos] === 10) { // \n
this.state = states.TYPE; this.state = states.TYPE;
pos += 1; pos += 1;