Commit 9b466678 authored by Pieter Noordhuis's avatar Pieter Noordhuis
Browse files

Move per-type actions to if-blocks

parent b919612b
...@@ -247,53 +247,42 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons ...@@ -247,53 +247,42 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
/* Protocol length can be set regardless of type */ /* Protocol length can be set regardless of type */
cur->plen = nread - cur->poff + 1; /* include \n */ cur->plen = nread - cur->poff + 1; /* include \n */
/* This should be done in the state machine itself, but I don't if (cur->type == REDIS_STRING_T) {
* want to dup the integer states for these three types. */ if (i64.i64 < 0) { /* nil bulk */
switch (cur->type) { CALLBACK(nil);
case REDIS_STRING_T: goto l_integer_lf_string_t; goto done;
case REDIS_ARRAY_T: goto l_integer_lf_array_t; }
case REDIS_INTEGER_T: goto l_integer_lf_integer_t;
default:
assert(NULL && "unexpected object type in s_integer_lf");
goto error;
}
l_integer_lf_string_t: /* Setup content offset and length */
/* Trap the nil bulk */ cur->coff = nread + 1; /* include \n */
if (i64.i64 < 0) { cur->clen = (unsigned)i64.i64;
CALLBACK(nil); cur->plen += cur->clen + 2; /* include \r\n */
goto done;
}
/* Setup content offset length. Note that the content length is /* Store remaining bytes for a complete bulk */
* known upfront, but not necessarily valid (we may see EOF cur->remaining = (unsigned)i64.i64;
* before seeing the last content byte). */ TRANSITION(bulk);
cur->coff = nread + 1; /* include \n */ }
cur->clen = (unsigned)i64.i64;
cur->plen += cur->clen + 2; /* include \r\n */
/* Store remaining bytes for a complete bulk */ if (cur->type == REDIS_ARRAY_T) {
cur->remaining = (unsigned)i64.i64; if (i64.i64 < 0) { /* nil multi bulk */
state = s_bulk; CALLBACK(nil);
break; goto done;
}
l_integer_lf_array_t: cur->remaining = (unsigned)i64.i64;
/* Trap the nil multi bulk */ CALLBACK(array, cur->remaining);
if (i64.i64 < 0) {
CALLBACK(nil);
goto done; goto done;
} }
cur->remaining = (unsigned)i64.i64; if (cur->type == REDIS_INTEGER_T) {
CALLBACK(array, cur->remaining); /* Setup content offset and length */
goto done; cur->coff = cur->poff + 1;
cur->clen = nread - cur->coff - 1; /* remove \r */
CALLBACK(integer, i64.i64);
goto done;
}
l_integer_lf_integer_t: assert(NULL && "unexpected object type in s_integer_lf");
/* Setup content offset and length */
cur->coff = cur->poff + 1;
cur->clen = nread - cur->coff - 1; /* remove \r */
CALLBACK(integer, i64.i64);
goto done;
} }
case s_bulk: case s_bulk:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment