aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Rogers <irogers@google.com>2024-05-08 22:13:17 -0700
committerSteven Rostedt (Google) <rostedt@goodmis.org>2024-05-17 15:11:18 -0400
commit8802f0f8761a9bdaf8c15223ce05389b7397ffbb (patch)
treee25a5ffb4917e6745a0f4fcbf9ac6381f1b8ec10
parent76a0eb8d5a20c69120a5f8b4c12f4da0cdc15bb5 (diff)
downloadlibtraceevent.tar.gz
libtraceevent: Avoid a simple asprintf caseHEADlibtraceevent
The asprintf function can cause some noticeable overhead[1] and using it for allocating just two characters is a little expensive. Avoid the asprintf for the single character TEP_EVENT_NEWLINE and TEP_EVENT_DELIM case. [1] https://lore.kernel.org/lkml/20240509052015.1914670-1-irogers@google.com/ Link: https://lore.kernel.org/linux-trace-devel/20240509051317.1913001-1-irogers@google.com Signed-off-by: Ian Rogers <irogers@google.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
-rw-r--r--src/event-parse.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/event-parse.c b/src/event-parse.c
index 2c38fe5..b625621 100644
--- a/src/event-parse.c
+++ b/src/event-parse.c
@@ -1232,9 +1232,11 @@ static enum tep_event_type __read_token(struct tep_handle *tep, char **tok)
switch (type) {
case TEP_EVENT_NEWLINE:
case TEP_EVENT_DELIM:
- if (asprintf(tok, "%c", ch) < 0)
+ *tok = malloc(2);
+ if (!*tok)
return TEP_EVENT_ERROR;
-
+ (*tok)[0] = ch;
+ (*tok)[1] = '\0';
return type;
case TEP_EVENT_OP: