Skip to content

Commit 617cc12

Browse files
committed
simplify a bit memory management during reconstruction of tsvector value
1 parent 0e413ce commit 617cc12

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

rum_ts_utils.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,11 @@ typedef struct RestoreWordEntry
532532
* reconstruct partial tsvector from set of index entries
533533
*/
534534
static TSVector
535-
rum_reconstruct_tsvector(bool *check, TSQuery query, int32 nkeys,
536-
int *map_item_operand,
535+
rum_reconstruct_tsvector(bool *check, TSQuery query, int *map_item_operand,
537536
Datum *addInfo, bool *addInfoIsNull)
538537
{
539538
TSVector tsv;
540-
int cntwords = 0,
541-
totalwords = query->size * 4;/* 4 positions per word, estimation */
539+
int cntwords = 0;
542540
int i = 0;
543541
QueryItem *item = GETQUERY(query);
544542
char *operandData = GETOPERAND(query);
@@ -550,8 +548,8 @@ rum_reconstruct_tsvector(bool *check, TSQuery query, int32 nkeys,
550548
int stroff;
551549

552550

553-
rwe = palloc(sizeof(*rwe) * totalwords);
554-
visited = palloc0(sizeof(*visited) * nkeys);
551+
rwe = palloc(sizeof(*rwe) * query->size);
552+
visited = palloc0(sizeof(*visited) * query->size);
555553

556554
/*
557555
* go through query to collect lexemes and add to them
@@ -562,7 +560,7 @@ rum_reconstruct_tsvector(bool *check, TSQuery query, int32 nkeys,
562560
{
563561
if (item->type == QI_VAL)
564562
{
565-
int keyN = map_item_operand[i];
563+
int keyN = map_item_operand[i];
566564

567565
if (check[keyN] == true && visited[keyN] == false)
568566
{
@@ -572,12 +570,6 @@ rum_reconstruct_tsvector(bool *check, TSQuery query, int32 nkeys,
572570
*/
573571
visited[keyN] = true;
574572

575-
while (cntwords + 1 >= totalwords)
576-
{
577-
totalwords *= 2;
578-
rwe = repalloc(rwe, sizeof(*rwe) * totalwords);
579-
}
580-
581573
rwe[cntwords].word = operandData + item->qoperand.distance;
582574
rwe[cntwords].wordlen = item->qoperand.length;
583575

@@ -662,15 +654,15 @@ rum_tsquery_distance(PG_FUNCTION_ARGS)
662654

663655
/* StrategyNumber strategy = PG_GETARG_UINT16(1); */
664656
TSQuery query = PG_GETARG_TSQUERY(2);
665-
int32 nkeys = PG_GETARG_INT32(3);
657+
/* int32 nkeys = PG_GETARG_INT32(3); */
666658
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
667659
Datum *addInfo = (Datum *) PG_GETARG_POINTER(8);
668660
bool *addInfoIsNull = (bool *) PG_GETARG_POINTER(9);
669661
float8 res;
670662
int *map_item_operand = (int *) (extra_data[0]);
671663
TSVector tsv;
672664

673-
tsv = rum_reconstruct_tsvector(check, query, nkeys, map_item_operand,
665+
tsv = rum_reconstruct_tsvector(check, query, map_item_operand,
674666
addInfo, addInfoIsNull);
675667

676668
res = DatumGetFloat4(DirectFunctionCall2Coll(ts_rank_tt,

0 commit comments

Comments
 (0)