From 19ed763285b27e717bbc7835b31098629682dd1f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 4 Mar 2016 11:31:00 -0500 Subject: [PATCH] Optimization: lttng UI uses sprintf instead of strcpy MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The LTTng client currently uses sprintf with format strings that don't contain a format specifier. Users have reported concerns for the scalability and performance of the LTTng UI because of this overkill use of sprintf instead of strcpy which, presumably, could be inlined by the compiler. Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/list.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index efa1abfd0..bcada31cd 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -214,6 +214,7 @@ static char *get_exclusion_names_msg(struct lttng_event *event) int count; size_t i; const char * const exclusion_fmt = " [exclusions: "; + const size_t exclusion_fmt_len = strlen(exclusion_fmt); exclusion_count = lttng_event_get_exclusion_name_count(event); if (exclusion_count < 0) { @@ -234,15 +235,12 @@ static char *get_exclusion_names_msg(struct lttng_event *event) */ exclusion_msg = malloc(exclusion_count + exclusion_count * LTTNG_SYMBOL_NAME_LEN + - strlen(exclusion_fmt) + 1); + exclusion_fmt_len + 1); if (!exclusion_msg) { goto end; } - at = exclusion_msg; - count = sprintf(at, exclusion_fmt); - at += count; - + at = strcpy(exclusion_msg, exclusion_fmt) + exclusion_fmt_len; for (i = 0; i < exclusion_count; ++i) { const char *name; @@ -266,7 +264,7 @@ static char *get_exclusion_names_msg(struct lttng_event *event) } /* This also puts a final '\0' at the end of exclusion_msg */ - sprintf(at, "]"); + strcpy(at, "]"); end: return exclusion_msg; -- 2.34.1