neels has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/33535 )
Change subject: mgcp_client: tweak extract_codec_name() implementation ......................................................................
mgcp_client: tweak extract_codec_name() implementation
Instead of calling strlen() for every loop iteration, just use strchr() to find the position of '/'.
Change-Id: Ifc7302b6c5f9288a622e33c3e8b5fe0e7037dbdc --- M src/libosmo-mgcp-client/mgcp_client.c 1 file changed, 16 insertions(+), 5 deletions(-)
Approvals: Jenkins Builder: Verified osmith: Looks good to me, but someone else must approve fixeria: Looks good to me, approved
diff --git a/src/libosmo-mgcp-client/mgcp_client.c b/src/libosmo-mgcp-client/mgcp_client.c index 75c7b14..78652a1 100644 --- a/src/libosmo-mgcp-client/mgcp_client.c +++ b/src/libosmo-mgcp-client/mgcp_client.c @@ -69,17 +69,16 @@ static char *extract_codec_name(const char *str) { static char buf[64]; - unsigned int i; + char *pos;
if (!str) return NULL;
osmo_strlcpy(buf, str, sizeof(buf));
- for (i = 0; i < strlen(buf); i++) { - if (buf[i] == '/') - buf[i] = '\0'; - } + pos = strchr(buf, '/'); + if (pos) + *pos = '\0';
return buf; }