Skip to content

Commit

Permalink
gobuffer: Add gobuffer__sort() helper
Browse files Browse the repository at this point in the history
Add a helper to sort the gobuffer. Trivial wrapper around qsort().

Committer notes:

As pointed out by Alan Maguire, there is no need to cast the first
qsort() argument to void, remove that cast.

Reviewed-by: Alan Maguire <[email protected]>
Signed-off-by: Daniel Xu <[email protected]>
Cc: Alexei Starovoitov <[email protected]>
Cc: Andrii Nakryiko <[email protected]>
Cc: Daniel Borkmann <[email protected]>
Cc: Eduard Zingerman <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Quentin Monnet <[email protected]>
Link: https://lore.kernel.org/r/ba9ff49e099583ab854d3d3c8c215c3ca1b6f930.1711389163.git.dxu@dxuuu.xyz
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
danobi authored and acmel committed Apr 23, 2024
1 parent 9aba4c9 commit 2046cc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gobuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ void gobuffer__copy(const struct gobuffer *gb, void *dest)
}
}

void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *))
{
qsort(gb->entries, gb->nr_entries, size, compar);
}

const void *gobuffer__compress(struct gobuffer *gb, unsigned int *size)
{
z_stream z = {
Expand Down
2 changes: 2 additions & 0 deletions gobuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void __gobuffer__delete(struct gobuffer *gb);

void gobuffer__copy(const struct gobuffer *gb, void *dest);

void gobuffer__sort(struct gobuffer *gb, unsigned int size, int (*compar)(const void *, const void *));

int gobuffer__add(struct gobuffer *gb, const void *s, unsigned int len);
int gobuffer__allocate(struct gobuffer *gb, unsigned int len);

Expand Down

0 comments on commit 2046cc5

Please sign in to comment.