Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitee01d84

Browse files
committed
In bms_add_member(), use repalloc() if the bms needs to be enlarged.
Previously bms_add_member() would palloc a whole-new copy of the existingset, copy the words, and pfree the old one. repalloc() is potentially muchfaster, and more importantly, this is less surprising if CurrentMemoryContextis not the same as the context the old set is in. bms_add_member() stillallocates a new bitmapset in CurrentMemoryContext if NULL is passed asargument, but that is a lot less likely to induce bugs.Nicholas White.
1 parent357f752 commitee01d84

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

‎src/backend/nodes/bitmapset.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -632,21 +632,20 @@ bms_add_member(Bitmapset *a, int x)
632632
returnbms_make_singleton(x);
633633
wordnum=WORDNUM(x);
634634
bitnum=BITNUM(x);
635+
636+
/* enlarge the set if necessary */
635637
if (wordnum >=a->nwords)
636638
{
637-
/* Slow path: make a larger set and union the input set into it */
638-
Bitmapset*result;
639-
intnwords;
639+
intoldnwords=a->nwords;
640640
inti;
641641

642-
result=bms_make_singleton(x);
643-
nwords=a->nwords;
644-
for (i=0;i<nwords;i++)
645-
result->words[i] |=a->words[i];
646-
pfree(a);
647-
returnresult;
642+
a= (Bitmapset*)repalloc(a,BITMAPSET_SIZE(wordnum+1));
643+
a->nwords=wordnum+1;
644+
/* zero out the enlarged portion */
645+
for (i=oldnwords;i<a->nwords;i++)
646+
a->words[i]=0;
648647
}
649-
/* Fast path: x fits in existing set */
648+
650649
a->words[wordnum] |= ((bitmapword)1 <<bitnum);
651650
returna;
652651
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp