Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
hiredis
Commits
9b466678
Commit
9b466678
authored
Jul 02, 2011
by
Pieter Noordhuis
Browse files
Move per-type actions to if-blocks
parent
b919612b
Changes
1
Show whitespace changes
Inline
Side-by-side
parser.c
View file @
9b466678
...
...
@@ -247,39 +247,24 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
/* Protocol length can be set regardless of type */
cur
->
plen
=
nread
-
cur
->
poff
+
1
;
/* include \n */
/* This should be done in the state machine itself, but I don't
* want to dup the integer states for these three types. */
switch
(
cur
->
type
)
{
case
REDIS_STRING_T
:
goto
l_integer_lf_string_t
;
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:
/* Trap the nil bulk */
if
(
i64
.
i64
<
0
)
{
if
(
cur
->
type
==
REDIS_STRING_T
)
{
if
(
i64
.
i64
<
0
)
{
/* nil bulk */
CALLBACK
(
nil
);
goto
done
;
}
/* Setup content offset length. Note that the content length is
* known upfront, but not necessarily valid (we may see EOF
* before seeing the last content byte). */
/* Setup content offset and length */
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 */
cur
->
remaining
=
(
unsigned
)
i64
.
i64
;
state
=
s_
bulk
;
break
;
TRANSITION
(
bulk
)
;
}
l_integer_lf_array_t:
/* Trap the nil multi bulk */
if
(
i64
.
i64
<
0
)
{
if
(
cur
->
type
==
REDIS_ARRAY_T
)
{
if
(
i64
.
i64
<
0
)
{
/* nil multi bulk */
CALLBACK
(
nil
);
goto
done
;
}
...
...
@@ -287,8 +272,9 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
cur
->
remaining
=
(
unsigned
)
i64
.
i64
;
CALLBACK
(
array
,
cur
->
remaining
);
goto
done
;
}
l_integer_lf_integer_t:
if
(
cur
->
type
==
REDIS_INTEGER_T
)
{
/* Setup content offset and length */
cur
->
coff
=
cur
->
poff
+
1
;
cur
->
clen
=
nread
-
cur
->
coff
-
1
;
/* remove \r */
...
...
@@ -296,6 +282,9 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
goto
done
;
}
assert
(
NULL
&&
"unexpected object type in s_integer_lf"
);
}
case
s_bulk
:
l_bulk:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment