The following commit has been merged into the perf/core branch of tip:
Commit-ID: 826100a7ce9a659b42140710ebe789d710799048
Gitweb: https://git.kernel.org/tip/826100a7ce9a659b42140710ebe789d710799048
Author: Ian Rogers [off-list ref]
AuthorDate: Tue, 22 Oct 2019 17:53:33 -07:00
Committer: Arnaldo Carvalho de Melo [off-list ref]
CommitterDate: Wed, 06 Nov 2019 15:43:05 -03:00
perf tools: Avoid a malloc() for array events
Use realloc() rather than malloc()+memcpy() to possibly avoid a memory
allocation when appending array elements.
Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Andi Kleen <redacted>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Jin Yao <redacted>
Cc: John Garry <redacted>
Cc: Kan Liang <redacted>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Martin KaFai Lau <redacted>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <redacted>
Cc: Stephane Eranian <redacted>
Cc: Yonghong Song <redacted>
Cc: <redacted>
Cc: <redacted>
Cc: <redacted>
Link: http://lore.kernel.org/lkml/20191023005337.196160-6-irogers@google.com (local)
Signed-off-by: Arnaldo Carvalho de Melo <redacted>
---
tools/perf/util/parse-events.y | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 5863acb..ffa1a1b 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -689,14 +689,12 @@ array_terms ',' array_term
struct parse_events_array new_array;
new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
- new_array.ranges = malloc(sizeof(new_array.ranges[0]) *
- new_array.nr_ranges);
+ new_array.ranges = realloc($1.ranges,
+ sizeof(new_array.ranges[0]) *
+ new_array.nr_ranges);
ABORT_ON(!new_array.ranges);
- memcpy(&new_array.ranges[0], $1.ranges,
- $1.nr_ranges * sizeof(new_array.ranges[0]));
memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
$3.nr_ranges * sizeof(new_array.ranges[0]));
- free($1.ranges);
free($3.ranges);
$$ = new_array;
}