diff options
author | Philip Prindeville <philipp@redfish-solutions.com> | 2023-04-14 12:37:06 -0600 |
---|---|---|
committer | Alexander Couzens <lynxis@fe80.eu> | 2023-04-16 14:53:11 +0200 |
commit | 5893cf78da4002eaf6caa01ff27134b3368c1161 (patch) | |
tree | 6edd24a58aa906def325bdb6c330835e42cb0f8b | |
parent | 6fc29d1c429240a9afb71c22aa161b066502f3ed (diff) | |
download | libubox-master.tar.gz |
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>
-rw-r--r-- | blobmsg_json.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/blobmsg_json.c b/blobmsg_json.c index dce81e9..ec8b482 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -151,15 +151,15 @@ static bool blobmsg_puts(struct strbuf *s, const char *c, int len) 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; if (!s->indent) return; len = s->indent_level + 1; - if (len > strlen(indent_chars)) - len = strlen(indent_chars); + if (len > sizeof(indent_chars) - 1) + len = sizeof(indent_chars) - 1; blobmsg_puts(s, indent_chars, len); } |