-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fmt: handy functions for pointer-length objects #884
Conversation
017836c
to
1582053
Compare
src/fmt/pl.c
Outdated
* | ||
* @return 0 if success, otherwise errorcode | ||
*/ | ||
int pl_hex(const struct pl *pl, uint8_t *hex, unsigned int len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use size_t
instead of unsigned int
src/fmt/pl.c
Outdated
*/ | ||
int pl_hex(const struct pl *pl, uint8_t *hex, unsigned int len) | ||
{ | ||
unsigned int i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using C99 style, this variable can be declared inside the for-loop.
Also please use size_t
src/fmt/pl.c
Outdated
if (pl->l - i < str_len(str)) | ||
return NULL; | ||
|
||
if (!memcmp(pl->p + i, str, str_len(str))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can cache the length of the string, it should speed up the function slightly ...
src/fmt/pl.c
Outdated
@@ -655,6 +678,39 @@ const char *pl_strrchr(const struct pl *pl, char c) | |||
} | |||
|
|||
|
|||
/** | |||
* Locate the fist substring in a pointer-length string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fist -> first
No description provided.