xyarray__realloc() could be used if we wish extend the evsel->fd, evsel->sample_id or any other xyarray on-the-fly.
Cc: David Ahern <[email protected]> Cc: Arjan van de Ven <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Yanmin Zhang <[email protected]> Cc: Wu Fengguang <[email protected]> Cc: Mike Galbraith <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: Chenggang Qin <[email protected]> --- tools/perf/util/xyarray.c | 26 ++++++++++++++++++++++++++ tools/perf/util/xyarray.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/tools/perf/util/xyarray.c b/tools/perf/util/xyarray.c index 22afbf6..4e76377 100644 --- a/tools/perf/util/xyarray.c +++ b/tools/perf/util/xyarray.c @@ -18,3 +18,29 @@ void xyarray__delete(struct xyarray *xy) { free(xy); } + +int xyarray__realloc(struct xyarray **xy_old, int xlen_old, int xlen_new, + int ylen_new) +{ + size_t row_size_new = ylen_new * (*xy_old)->entry_size; + struct xyarray *xy_new = zalloc(sizeof(*xy_new) + xlen_new + * row_size_new); + int x; + + if (xy_new != NULL) { + for (x = 0; x < xlen_old; x++) + memcpy(&xy_new->contents[x * row_size_new], + &((*xy_old)->contents[x * (*xy_old)->row_size]), + (*xy_old)->row_size); + + xy_new->row_size = row_size_new; + xy_new->entry_size = (*xy_old)->entry_size; + + xyarray__delete(*xy_old); + + *xy_old = xy_new; + + return 0; + } + + return -1; +} + diff --git a/tools/perf/util/xyarray.h b/tools/perf/util/xyarray.h index c488a07..ad41649 100644 --- a/tools/perf/util/xyarray.h +++ b/tools/perf/util/xyarray.h @@ -11,6 +11,8 @@ struct xyarray { struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size); void xyarray__delete(struct xyarray *xy); +int xyarray__realloc(struct xyarray **xy_old, int xlen_old, int xlen_new, + int ylen_new); static inline void *xyarray__entry(struct xyarray *xy, int x, int y) { -- 1.7.9.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/

