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
397fe263
Commit
397fe263
authored
Oct 15, 2020
by
Alex Smith
Committed by
michael-grunder
Feb 25, 2021
Browse files
read: Use memchr() in seekNewline() instead of looping over entire string
parent
81c48a98
Changes
1
Show whitespace changes
Inline
Side-by-side
read.c
View file @
397fe263
...
...
@@ -123,29 +123,22 @@ static char *readBytes(redisReader *r, unsigned int bytes) {
/* Find pointer to \r\n. */
static
char
*
seekNewline
(
char
*
s
,
size_t
len
)
{
int
pos
=
0
;
char
*
_s
=
s
,
*
ret
;
int
_len
=
len
-
1
;
/* Position should be < len-1 because the character at "pos" should be
* followed by a \n. Note that strchr cannot be used because it doesn't
* allow to search a limited length and the buffer that is being searched
* might not have a trailing NULL character. */
while
(
pos
<
_len
)
{
while
(
pos
<
_len
&&
s
[
pos
]
!=
'\r'
)
pos
++
;
if
(
pos
==
_len
)
{
/* Not found. */
return
NULL
;
}
else
{
if
(
s
[
pos
+
1
]
==
'\n'
)
{
/* Exclude the last character from the searched length because the found
* '\r' should be followed by a '\n' */
while
((
ret
=
memchr
(
_s
,
'\r'
,
_len
))
!=
NULL
)
{
if
(
ret
[
1
]
==
'\n'
)
{
/* Found. */
return
s
+
pos
;
}
else
{
/* Continue searching. */
pos
++
;
}
break
;
}
/* Continue searching. */
ret
++
;
_len
-=
ret
-
_s
;
_s
=
ret
;
}
return
NULL
;
return
ret
;
}
/* Convert a string into a long long. Returns REDIS_OK if the string could be
...
...
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