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
e5f11931
Commit
e5f11931
authored
Jul 05, 2011
by
Pieter Noordhuis
Browse files
Only use char when really necessary
parent
bf14e87a
Changes
1
Hide whitespace changes
Inline
Side-by-side
parser.c
View file @
e5f11931
...
@@ -56,8 +56,7 @@ static const char * strstate[] = {
...
@@ -56,8 +56,7 @@ static const char * strstate[] = {
state = s_##st; \
state = s_##st; \
if (pos >= end) {
/* No more data */
\
if (pos >= end) {
/* No more data */
\
goto finalize; \
goto finalize; \
} \
}
ch = *pos;
#define TRANSITION(st) do { \
#define TRANSITION(st) do { \
pos++; nread++; \
pos++; nread++; \
...
@@ -131,7 +130,6 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -131,7 +130,6 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
unsigned
char
state
;
unsigned
char
state
;
struct
redis_parser_int64_s
i64
;
struct
redis_parser_int64_s
i64
;
redis_protocol_t
*
cur
;
redis_protocol_t
*
cur
;
char
ch
;
/* Reset destination */
/* Reset destination */
if
(
dst
)
*
dst
=
NULL
;
if
(
dst
)
*
dst
=
NULL
;
...
@@ -160,7 +158,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -160,7 +158,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
STATE
(
type_char
)
{
STATE
(
type_char
)
{
cur
->
poff
=
nread
;
cur
->
poff
=
nread
;
switch
(
ch
)
{
switch
(
*
pos
)
{
case
'$'
:
case
'$'
:
cur
->
type
=
REDIS_STRING_T
;
cur
->
type
=
REDIS_STRING_T
;
TRANSITION
(
integer_start
);
TRANSITION
(
integer_start
);
...
@@ -182,6 +180,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -182,6 +180,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
}
}
STATE
(
integer_start
)
{
STATE
(
integer_start
)
{
char
ch
=
*
pos
;
i64
.
neg
=
0
;
i64
.
neg
=
0
;
i64
.
ui64
=
0
;
i64
.
ui64
=
0
;
...
@@ -212,6 +211,8 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -212,6 +211,8 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
}
}
STATE
(
integer_19
)
{
STATE
(
integer_19
)
{
char
ch
=
*
pos
;
if
(
ch
>=
'1'
&&
ch
<=
'9'
)
{
if
(
ch
>=
'1'
&&
ch
<=
'9'
)
{
i64
.
ui64
=
ch
-
'0'
;
i64
.
ui64
=
ch
-
'0'
;
TRANSITION
(
integer_09
);
TRANSITION
(
integer_09
);
...
@@ -221,6 +222,8 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -221,6 +222,8 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
}
}
STATE
(
integer_09
)
{
STATE
(
integer_09
)
{
char
ch
=
*
pos
;
if
(
ch
>=
'0'
&&
ch
<=
'9'
)
{
if
(
ch
>=
'0'
&&
ch
<=
'9'
)
{
if
(
i64
.
ui64
>
(
UINT64_MAX
/
10
))
/* Overflow */
if
(
i64
.
ui64
>
(
UINT64_MAX
/
10
))
/* Overflow */
goto
error
;
goto
error
;
...
@@ -237,7 +240,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -237,7 +240,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
}
}
STATE
(
integer_cr
)
{
STATE
(
integer_cr
)
{
if
(
ch
==
'\r'
)
{
if
(
*
pos
==
'\r'
)
{
TRANSITION
(
integer_lf
);
TRANSITION
(
integer_lf
);
}
}
...
@@ -245,7 +248,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -245,7 +248,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
}
}
STATE
(
integer_lf
)
{
STATE
(
integer_lf
)
{
if
(
ch
!=
'\n'
)
{
if
(
*
pos
!=
'\n'
)
{
goto
error
;
goto
error
;
}
}
...
@@ -322,7 +325,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -322,7 +325,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
}
}
STATE
(
bulk_cr
)
{
STATE
(
bulk_cr
)
{
if
(
ch
==
'\r'
)
{
if
(
*
pos
==
'\r'
)
{
TRANSITION
(
bulk_lf
);
TRANSITION
(
bulk_lf
);
}
}
...
@@ -330,7 +333,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
...
@@ -330,7 +333,7 @@ size_t redis_parser_execute(redis_parser_t *parser, redis_protocol_t **dst, cons
}
}
STATE
(
bulk_lf
)
{
STATE
(
bulk_lf
)
{
if
(
ch
==
'\n'
)
{
if
(
*
pos
==
'\n'
)
{
goto
done
;
goto
done
;
}
}
...
...
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