mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-28 14:52:43 +08:00
Switched to palloc_object and palloc0_object when possible
This commit is contained in:
@@ -105,6 +105,11 @@ typedef Pointer Item;
|
||||
#define SeedRandom(seed) srandom(seed)
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 160000
|
||||
#define palloc_object(type) ((type *) palloc(sizeof(type)))
|
||||
#define palloc0_object(type) ((type *) palloc0(sizeof(type)))
|
||||
#endif
|
||||
|
||||
#define HnswIsElementTuple(tup) ((tup)->type == HNSW_ELEMENT_TUPLE_TYPE)
|
||||
#define HnswIsNeighborTuple(tup) ((tup)->type == HNSW_NEIGHBOR_TUPLE_TYPE)
|
||||
|
||||
|
||||
@@ -930,7 +930,7 @@ HnswBeginParallel(HnswBuildState * buildstate, bool isconcurrent, int request)
|
||||
Size estother;
|
||||
HnswShared *hnswshared;
|
||||
char *hnswarea;
|
||||
HnswLeader *hnswleader = (HnswLeader *) palloc0(sizeof(HnswLeader));
|
||||
HnswLeader *hnswleader = palloc0_object(HnswLeader);
|
||||
bool leaderparticipates = true;
|
||||
int querylen;
|
||||
|
||||
@@ -1151,7 +1151,7 @@ hnswbuild(Relation heap, Relation index, IndexInfo *indexInfo)
|
||||
|
||||
BuildIndex(heap, index, indexInfo, &buildstate, MAIN_FORKNUM);
|
||||
|
||||
result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
|
||||
result = palloc_object(IndexBuildResult);
|
||||
result->heap_tuples = buildstate.reltuples;
|
||||
result->index_tuples = buildstate.indtuples;
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@ hnswbeginscan(Relation index, int nkeys, int norderbys)
|
||||
|
||||
scan = RelationGetIndexScan(index, nkeys, norderbys);
|
||||
|
||||
so = (HnswScanOpaque) palloc(sizeof(HnswScanOpaqueData));
|
||||
so = palloc_object(HnswScanOpaqueData);
|
||||
so->typeInfo = HnswGetTypeInfo(index);
|
||||
|
||||
/* Set support functions */
|
||||
|
||||
@@ -282,7 +282,7 @@ HnswAddHeapTid(HnswElement element, ItemPointer heaptid)
|
||||
HnswElement
|
||||
HnswInitElementFromBlock(BlockNumber blkno, OffsetNumber offno)
|
||||
{
|
||||
HnswElement element = palloc(sizeof(HnswElementData));
|
||||
HnswElement element = palloc_object(HnswElementData);
|
||||
char *base = NULL;
|
||||
|
||||
element->blkno = blkno;
|
||||
@@ -596,7 +596,7 @@ GetElementDistance(char *base, HnswElement element, HnswQuery * q, HnswSupport *
|
||||
static HnswSearchCandidate *
|
||||
HnswInitSearchCandidate(char *base, HnswElement element, double distance)
|
||||
{
|
||||
HnswSearchCandidate *sc = palloc(sizeof(HnswSearchCandidate));
|
||||
HnswSearchCandidate *sc = palloc_object(HnswSearchCandidate);
|
||||
|
||||
HnswPtrStore(base, sc->element, element);
|
||||
sc->distance = distance;
|
||||
@@ -1328,7 +1328,7 @@ HnswFindElementNeighbors(char *base, HnswElement element, HnswElement entryPoint
|
||||
foreach(lc2, w)
|
||||
{
|
||||
HnswSearchCandidate *sc = lfirst(lc2);
|
||||
HnswCandidate *hc = palloc(sizeof(HnswCandidate));
|
||||
HnswCandidate *hc = palloc_object(HnswCandidate);
|
||||
|
||||
hc->element = sc->element;
|
||||
hc->distance = sc->distance;
|
||||
|
||||
@@ -737,7 +737,7 @@ InitVacuumState(HnswVacuumState * vacuumstate, IndexVacuumInfo *info, IndexBulkD
|
||||
Relation index = info->index;
|
||||
|
||||
if (stats == NULL)
|
||||
stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
|
||||
stats = palloc0_object(IndexBulkDeleteResult);
|
||||
|
||||
vacuumstate->index = index;
|
||||
vacuumstate->stats = stats;
|
||||
|
||||
@@ -662,7 +662,7 @@ IvfflatParallelScanAndSort(IvfflatSpool * ivfspool, IvfflatShared * ivfshared, S
|
||||
IndexInfo *indexInfo;
|
||||
|
||||
/* Initialize local tuplesort coordination state */
|
||||
coordinate = palloc0(sizeof(SortCoordinateData));
|
||||
coordinate = palloc0_object(SortCoordinateData);
|
||||
coordinate->isWorker = true;
|
||||
coordinate->nParticipants = -1;
|
||||
coordinate->sharedsort = sharedsort;
|
||||
@@ -757,7 +757,7 @@ IvfflatParallelBuildMain(dsm_segment *seg, shm_toc *toc)
|
||||
indexRel = index_open(ivfshared->indexrelid, indexLockmode);
|
||||
|
||||
/* Initialize worker's own spool */
|
||||
ivfspool = (IvfflatSpool *) palloc0(sizeof(IvfflatSpool));
|
||||
ivfspool = palloc0_object(IvfflatSpool);
|
||||
ivfspool->heap = heapRel;
|
||||
ivfspool->index = indexRel;
|
||||
|
||||
@@ -812,7 +812,7 @@ IvfflatLeaderParticipateAsWorker(IvfflatBuildState * buildstate)
|
||||
int sortmem;
|
||||
|
||||
/* Allocate memory and initialize private spool */
|
||||
leaderworker = (IvfflatSpool *) palloc0(sizeof(IvfflatSpool));
|
||||
leaderworker = palloc0_object(IvfflatSpool);
|
||||
leaderworker->heap = buildstate->heap;
|
||||
leaderworker->index = buildstate->index;
|
||||
|
||||
@@ -838,7 +838,7 @@ IvfflatBeginParallel(IvfflatBuildState * buildstate, bool isconcurrent, int requ
|
||||
IvfflatShared *ivfshared;
|
||||
Sharedsort *sharedsort;
|
||||
char *ivfcenters;
|
||||
IvfflatLeader *ivfleader = (IvfflatLeader *) palloc0(sizeof(IvfflatLeader));
|
||||
IvfflatLeader *ivfleader = palloc0_object(IvfflatLeader);
|
||||
bool leaderparticipates = true;
|
||||
int querylen;
|
||||
|
||||
@@ -987,7 +987,7 @@ AssignTuples(IvfflatBuildState * buildstate)
|
||||
/* Set up coordination state if at least one worker launched */
|
||||
if (buildstate->ivfleader)
|
||||
{
|
||||
coordinate = (SortCoordinate) palloc0(sizeof(SortCoordinateData));
|
||||
coordinate = palloc0_object(SortCoordinateData);
|
||||
coordinate->isWorker = false;
|
||||
coordinate->nParticipants = buildstate->ivfleader->nparticipanttuplesorts;
|
||||
coordinate->sharedsort = buildstate->ivfleader->sharedsort;
|
||||
@@ -1072,7 +1072,7 @@ ivfflatbuild(Relation heap, Relation index, IndexInfo *indexInfo)
|
||||
|
||||
BuildIndex(heap, index, indexInfo, &buildstate, MAIN_FORKNUM);
|
||||
|
||||
result = (IndexBuildResult *) palloc(sizeof(IndexBuildResult));
|
||||
result = palloc_object(IndexBuildResult);
|
||||
result->heap_tuples = buildstate.reltuples;
|
||||
result->index_tuples = buildstate.indtuples;
|
||||
|
||||
|
||||
@@ -89,6 +89,11 @@ typedef Pointer Item;
|
||||
#define SeedRandom(seed) srandom(seed)
|
||||
#endif
|
||||
|
||||
#if PG_VERSION_NUM < 160000
|
||||
#define palloc_object(type) ((type *) palloc(sizeof(type)))
|
||||
#define palloc0_object(type) ((type *) palloc0(sizeof(type)))
|
||||
#endif
|
||||
|
||||
/* Variables */
|
||||
extern int ivfflat_probes;
|
||||
extern int ivfflat_iterative_scan;
|
||||
|
||||
@@ -276,7 +276,7 @@ ivfflatbeginscan(Relation index, int nkeys, int norderbys)
|
||||
if (maxProbes > lists)
|
||||
maxProbes = lists;
|
||||
|
||||
so = (IvfflatScanOpaque) palloc(sizeof(IvfflatScanOpaqueData));
|
||||
so = palloc_object(IvfflatScanOpaqueData);
|
||||
so->typeInfo = IvfflatGetTypeInfo(index);
|
||||
so->first = true;
|
||||
so->probes = probes;
|
||||
|
||||
@@ -31,7 +31,7 @@ VectorArrayInit(int maxlen, int dimensions, Size itemsize)
|
||||
/* Ensure items are aligned to prevent UB */
|
||||
itemsize = MAXALIGN(itemsize);
|
||||
|
||||
res = palloc(sizeof(VectorArrayData));
|
||||
res = palloc_object(VectorArrayData);
|
||||
res->length = 0;
|
||||
res->maxlen = maxlen;
|
||||
res->dim = dimensions;
|
||||
|
||||
@@ -24,7 +24,7 @@ ivfflatbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats,
|
||||
BufferAccessStrategy bas = GetAccessStrategy(BAS_BULKREAD);
|
||||
|
||||
if (stats == NULL)
|
||||
stats = (IndexBulkDeleteResult *) palloc0(sizeof(IndexBulkDeleteResult));
|
||||
stats = palloc0_object(IndexBulkDeleteResult);
|
||||
|
||||
/* Iterate over list pages */
|
||||
while (BlockNumberIsValid(blkno))
|
||||
|
||||
Reference in New Issue
Block a user