mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
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
This commit is contained in:
21
src/backend/utils/cache/syscache.c
vendored
21
src/backend/utils/cache/syscache.c
vendored
@ -74,6 +74,7 @@
|
||||
#include "catalog/pg_ts_template.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "catalog/pg_user_mapping.h"
|
||||
#include "lib/qunique.h"
|
||||
#include "utils/rel.h"
|
||||
#include "utils/catcache.h"
|
||||
#include "utils/syscache.h"
|
||||
@ -1010,8 +1011,6 @@ void
|
||||
InitCatalogCache(void)
|
||||
{
|
||||
int cacheId;
|
||||
int i,
|
||||
j;
|
||||
|
||||
StaticAssertStmt(SysCacheSize == (int) lengthof(cacheinfo),
|
||||
"SysCacheSize does not match syscache.c's array");
|
||||
@ -1048,21 +1047,15 @@ InitCatalogCache(void)
|
||||
/* Sort and de-dup OID arrays, so we can use binary search. */
|
||||
pg_qsort(SysCacheRelationOid, SysCacheRelationOidSize,
|
||||
sizeof(Oid), oid_compare);
|
||||
for (i = 1, j = 0; i < SysCacheRelationOidSize; i++)
|
||||
{
|
||||
if (SysCacheRelationOid[i] != SysCacheRelationOid[j])
|
||||
SysCacheRelationOid[++j] = SysCacheRelationOid[i];
|
||||
}
|
||||
SysCacheRelationOidSize = j + 1;
|
||||
SysCacheRelationOidSize =
|
||||
qunique(SysCacheRelationOid, SysCacheRelationOidSize, sizeof(Oid),
|
||||
oid_compare);
|
||||
|
||||
pg_qsort(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize,
|
||||
sizeof(Oid), oid_compare);
|
||||
for (i = 1, j = 0; i < SysCacheSupportingRelOidSize; i++)
|
||||
{
|
||||
if (SysCacheSupportingRelOid[i] != SysCacheSupportingRelOid[j])
|
||||
SysCacheSupportingRelOid[++j] = SysCacheSupportingRelOid[i];
|
||||
}
|
||||
SysCacheSupportingRelOidSize = j + 1;
|
||||
SysCacheSupportingRelOidSize =
|
||||
qunique(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize,
|
||||
sizeof(Oid), oid_compare);
|
||||
|
||||
CacheInitialized = true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user