diff options
author | Thomas Munro <tmunro@postgresql.org> | 2019-11-07 16:51:04 +1300 |
---|---|---|
committer | Thomas Munro <tmunro@postgresql.org> | 2019-11-07 17:00:48 +1300 |
commit | 7815e7efdb4ce9575b5d8460beb0dd2569d7ca3a (patch) | |
tree | dc3d1795259ab8c2dafc371cbd89725b43abc2da /src/backend/utils/adt/acl.c | |
parent | 3feb6ace7cfe8edbf6db702de06dc9295f307a8e (diff) |
Add reusable routine for making arrays unique.
Introduce qunique() and qunique_arg(), which can be used after qsort()
and qsort_arg() respectively to remove duplicate values. Use it where
appropriate.
Author: Thomas Munro
Reviewed-by: Tom Lane (in an earlier version)
Discussion: https://postgr.es/m/CAEepm%3D2vmFTNpAmwbGGD2WaryM6T3hSDVKQPfUwjdD_5XY6vAA%40mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/acl.c')
-rw-r--r-- | src/backend/utils/adt/acl.c | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/backend/utils/adt/acl.c b/src/backend/utils/adt/acl.c index d7e6100ccbf..79bc750d775 100644 --- a/src/backend/utils/adt/acl.c +++ b/src/backend/utils/adt/acl.c @@ -28,6 +28,7 @@ #include "commands/tablespace.h" #include "foreign/foreign.h" #include "funcapi.h" +#include "lib/qunique.h" #include "miscadmin.h" #include "utils/acl.h" #include "utils/array.h" @@ -1475,8 +1476,7 @@ aclmembers(const Acl *acl, Oid **roleids) Oid *list; const AclItem *acldat; int i, - j, - k; + j; if (acl == NULL || ACL_NUM(acl) == 0) { @@ -1508,21 +1508,14 @@ aclmembers(const Acl *acl, Oid **roleids) /* Sort the array */ qsort(list, j, sizeof(Oid), oid_cmp); - /* Remove duplicates from the array */ - k = 0; - for (i = 1; i < j; i++) - { - if (list[k] != list[i]) - list[++k] = list[i]; - } - /* * We could repalloc the array down to minimum size, but it's hardly worth * it since it's only transient memory. */ *roleids = list; - return k + 1; + /* Remove duplicates from the array */ + return qunique(list, j, sizeof(Oid), oid_cmp); } |