blobmsg: Don't do at run-time what can be done at compile-time

Repeatedly calling a run-time function like strlen() on an
invariant value is inefficient, especially if that value can be
computed once (at initialization) or better yet, computed at
compile-time.

Signed-off-by: Philip Prindeville <philipp@redfish-solutions.com>
This commit is contained in:
Philip Prindeville 2023-04-14 12:37:06 -06:00 committed by Alexander Couzens
parent 6fc29d1c42
commit 5893cf78da
No known key found for this signature in database
GPG key ID: 33D274667C49F55D

View file

@ -151,15 +151,15 @@ static bool blobmsg_puts(struct strbuf *s, const char *c, int len)
static void add_separator(struct strbuf *s) static void add_separator(struct strbuf *s)
{ {
const char *indent_chars = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; const char indent_chars[] = "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
size_t len; size_t len;
if (!s->indent) if (!s->indent)
return; return;
len = s->indent_level + 1; len = s->indent_level + 1;
if (len > strlen(indent_chars)) if (len > sizeof(indent_chars) - 1)
len = strlen(indent_chars); len = sizeof(indent_chars) - 1;
blobmsg_puts(s, indent_chars, len); blobmsg_puts(s, indent_chars, len);
} }