Skip to content

Commit 4caa336

Browse files
committed
5% improvements by eliminationg visited array in rum_reconstruct_tsvector()
1 parent 48aae44 commit 4caa336

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

rum_ts_utils.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -540,14 +540,12 @@ rum_reconstruct_tsvector(bool *check, TSQuery query, int *map_item_operand,
540540
int32 wordlen;
541541
} *restoredWordEntry;
542542
int len = 0, totallen;
543-
bool *visited;
544543
WordEntry *ptr;
545544
char *str;
546545
int stroff;
547546

548547

549548
restoredWordEntry = palloc(sizeof(*restoredWordEntry) * query->size);
550-
visited = palloc0(sizeof(*visited) * query->size);
551549

552550
/*
553551
* go through query to collect lexemes and add to them
@@ -560,13 +558,13 @@ rum_reconstruct_tsvector(bool *check, TSQuery query, int *map_item_operand,
560558
{
561559
int keyN = map_item_operand[i];
562560

563-
if (check[keyN] == true && visited[keyN] == false)
561+
if (check[keyN] == true)
564562
{
565563
/*
566564
* entries could be repeated in tsquery, do not visit them twice
567-
* or more
565+
* or more. Modifying of check array (entryRes) is safe
568566
*/
569-
visited[keyN] = true;
567+
check[keyN] = false;
570568

571569
restoredWordEntry[cntwords].word = operandData + item->qoperand.distance;
572570
restoredWordEntry[cntwords].wordlen = item->qoperand.length;
@@ -640,7 +638,6 @@ rum_reconstruct_tsvector(bool *check, TSQuery query, int *map_item_operand,
640638
}
641639

642640
pfree(restoredWordEntry);
643-
pfree(visited);
644641

645642
return tsv;
646643
}

0 commit comments

Comments
 (0)