optimized updatestatus by using library functions

This commit is contained in:
Ashish Kumar Yadav 2021-02-09 20:51:47 +05:30
parent ffd1403114
commit 07f444980d

View file

@ -244,33 +244,30 @@ int
updatestatus() updatestatus()
{ {
char *s = statustext; char *s = statustext;
char *c, *p; size_t len;
Block *block = blocks; Block *block = blocks;
/* checking half of the function */ /* checking half of the function */
for (; block->pathu; block++) { for (; block->pathu; block++) {
c = block->curcmdout, p = block->prvcmdout; len = strlen(block->curcmdout);
for (; *c != '\0' && *c == *p; c++, p++); if (memcmp(block->curcmdout, block->prvcmdout, len + 1) != 0)
s += c - block->curcmdout;
if (*c != *p)
goto update; goto update;
if (c == block->curcmdout) if (len == 0)
continue; continue;
if (block->pathc /* && block->signal */) s += len + (block->pathc ? 1 : 0) + DELIMITERLENGTH;
s++;
s += DELIMITERLENGTH;
} }
return 0; return 0;
/* updating half of the function */ /* updating half of the function */
for (; block->pathu; block++) { for (; block->pathu; block++) {
c = block->curcmdout, p = block->prvcmdout; len = strlen(block->curcmdout);
update: update:
for (; (*p = *c) != '\0'; c++, p++) memcpy(block->prvcmdout, block->curcmdout, len + 1);
*(s++) = *c; if (len == 0)
if (c == block->curcmdout)
continue; continue;
if (block->pathc /* && block->signal */) memcpy(s, block->curcmdout, len);
s += len;
if (block->pathc)
*(s++) = block->signal; *(s++) = block->signal;
memcpy(s, delimiter, DELIMITERLENGTH); memcpy(s, delimiter, DELIMITERLENGTH);
s += DELIMITERLENGTH; s += DELIMITERLENGTH;