Skip to content

Commit

Permalink
Optimize: egg_snprintf(newmsg) only if we have to and no need to strl…
Browse files Browse the repository at this point in the history
…en() when we already got the len returned from snprintf()
  • Loading branch information
Michael Ortmann committed Oct 16, 2023
1 parent 5f2e79c commit 1185f99
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/mod/server.mod/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,7 @@ static void parse_q(struct msgq_head *q, char *oldnick, char *newnick)
} else
snprintf(newnicks, sizeof newnicks, ",%s", nick);
}
egg_snprintf(newmsg, sizeof newmsg, "KICK %s %s %s", chan,
newnicks + 1, msg);

}
if (changed) {
if (newnicks[0] == 0) {
Expand All @@ -611,9 +610,11 @@ static void parse_q(struct msgq_head *q, char *oldnick, char *newnick)
if (!q->head)
q->last = 0;
} else {
len = egg_snprintf(newmsg, sizeof newmsg, "KICK %s %s %s", chan,
newnicks + 1, msg);
nfree(m->msg);
m->msg = nmalloc(strlen(newmsg) + 1);
m->len = strlen(newmsg);
m->msg = nmalloc(len + 1);
m->len = len;
strcpy(m->msg, newmsg);
}
}
Expand Down

0 comments on commit 1185f99

Please sign in to comment.