Skip to content
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

Merged
merged 5 commits into from
Jul 26, 2023

Conversation

cHuberCoffee
Copy link
Contributor

No description provided.

src/fmt/pl.c Outdated
*
* @return 0 if success, otherwise errorcode
*/
int pl_hex(const struct pl *pl, uint8_t *hex, unsigned int len)
Copy link
Contributor

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;
Copy link
Contributor

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)))
Copy link
Contributor

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fist -> first

@alfredh alfredh merged commit 1880cb9 into baresip:main Jul 26, 2023
@cHuberCoffee cHuberCoffee deleted the pl_functions branch July 26, 2023 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants