Replace calls to pg_qsort() with the qsort() macro.
authorNathan Bossart <nathan@postgresql.org>
Fri, 16 Feb 2024 17:37:50 +0000 (11:37 -0600)
committerNathan Bossart <nathan@postgresql.org>
Fri, 16 Feb 2024 17:37:50 +0000 (11:37 -0600)
Calls to this function might give the impression that pg_qsort()
is somehow different than qsort(), when in fact there is a qsort()
macro in port.h that expands all in-tree uses to pg_qsort().

Reviewed-by: Mats Kindahl
Discussion: https://postgr.es/m/CA%2B14426g2Wa9QuUpmakwPxXFWG_1FaY0AsApkvcTBy-YfS6uaw%40mail.gmail.com

contrib/pg_prewarm/autoprewarm.c
src/backend/access/brin/brin_minmax_multi.c
src/backend/optimizer/plan/analyzejoins.c
src/backend/storage/buffer/bufmgr.c
src/backend/utils/cache/syscache.c
src/include/port.h

index 06ee21d49631112050d9594f512232de5c8172fa..248b9914a3adf72e8b78caa87b51ad24699ec208 100644 (file)
@@ -346,8 +346,8 @@ apw_load_buffers(void)
    FreeFile(file);
 
    /* Sort the blocks to be loaded. */
-   pg_qsort(blkinfo, num_elements, sizeof(BlockInfoRecord),
-            apw_compare_blockinfo);
+   qsort(blkinfo, num_elements, sizeof(BlockInfoRecord),
+         apw_compare_blockinfo);
 
    /* Populate shared memory state. */
    apw_state->block_info_handle = dsm_segment_handle(seg);
index 3ffaad3e42de4726637d5886005418b2740530fa..2c29aa3d4efe35786fc73693c9953e3a3d32dacd 100644 (file)
@@ -1369,7 +1369,7 @@ build_distances(FmgrInfo *distanceFn, Oid colloid,
     * Sort the distances in descending order, so that the longest gaps are at
     * the front.
     */
-   pg_qsort(distances, ndistances, sizeof(DistanceValue), compare_distances);
+   qsort(distances, ndistances, sizeof(DistanceValue), compare_distances);
 
    return distances;
 }
index 7dcb74572ade08169634fef8e109c136986e9574..e494acd51a6b485e44c757f0e4ee49d0742fff85 100644 (file)
@@ -2307,8 +2307,8 @@ remove_self_joins_recurse(PlannerInfo *root, List *joinlist, Relids toRemove)
        j++;
    }
 
-   pg_qsort(candidates, numRels, sizeof(SelfJoinCandidate),
-            self_join_candidates_cmp);
+   qsort(candidates, numRels, sizeof(SelfJoinCandidate),
+         self_join_candidates_cmp);
 
    /*
     * Iteratively form a group of relation indexes with the same oid and
index eb1ec3b86df884ea7676e12e9857d1af4f71632c..07575ef31299abdc70562ae50e983fe112bcf5d8 100644 (file)
@@ -3915,7 +3915,7 @@ DropRelationsAllBuffers(SMgrRelation *smgr_reln, int nlocators)
 
    /* sort the list of rlocators if necessary */
    if (use_bsearch)
-       pg_qsort(locators, n, sizeof(RelFileLocator), rlocator_comparator);
+       qsort(locators, n, sizeof(RelFileLocator), rlocator_comparator);
 
    for (i = 0; i < NBuffers; i++)
    {
@@ -4269,7 +4269,7 @@ FlushRelationsAllBuffers(SMgrRelation *smgrs, int nrels)
 
    /* sort the list of SMgrRelations if necessary */
    if (use_bsearch)
-       pg_qsort(srels, nrels, sizeof(SMgrSortArray), rlocator_comparator);
+       qsort(srels, nrels, sizeof(SMgrSortArray), rlocator_comparator);
 
    for (i = 0; i < NBuffers; i++)
    {
index 162855b1587b0eb3b142479481ac1b611004d394..662f93086472db57b6cf885f0a04767042f051e4 100644 (file)
@@ -146,14 +146,14 @@ InitCatalogCache(void)
    Assert(SysCacheSupportingRelOidSize <= lengthof(SysCacheSupportingRelOid));
 
    /* Sort and de-dup OID arrays, so we can use binary search. */
-   pg_qsort(SysCacheRelationOid, SysCacheRelationOidSize,
-            sizeof(Oid), oid_compare);
+   qsort(SysCacheRelationOid, SysCacheRelationOidSize,
+         sizeof(Oid), oid_compare);
    SysCacheRelationOidSize =
        qunique(SysCacheRelationOid, SysCacheRelationOidSize, sizeof(Oid),
                oid_compare);
 
-   pg_qsort(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize,
-            sizeof(Oid), oid_compare);
+   qsort(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize,
+         sizeof(Oid), oid_compare);
    SysCacheSupportingRelOidSize =
        qunique(SysCacheSupportingRelOid, SysCacheSupportingRelOidSize,
                sizeof(Oid), oid_compare);
@@ -668,7 +668,7 @@ RelationSupportsSysCache(Oid relid)
 
 
 /*
- * OID comparator for pg_qsort
+ * OID comparator for qsort
  */
 static int
 oid_compare(const void *a, const void *b)
index 263cf791a392259909bc45a9a5f8c44c643afd21..ae115d2d970d2ae6a7fdeb4c9a9de13ee90a678b 100644 (file)
@@ -438,6 +438,10 @@ extern bool pg_get_user_name(uid_t user_id, char *buffer, size_t buflen);
 extern bool pg_get_user_home_dir(uid_t user_id, char *buffer, size_t buflen);
 #endif
 
+/*
+ * Callers should use the qsort() macro defined below instead of calling
+ * pg_qsort() directly.
+ */
 extern void pg_qsort(void *base, size_t nel, size_t elsize,
                     int (*cmp) (const void *, const void *));
 extern int pg_qsort_strcmp(const void *a, const void *b);