Re: Strange Bitmapset manipulation in DiscreteKnapsack()
От | Richard Guo |
---|---|
Тема | Re: Strange Bitmapset manipulation in DiscreteKnapsack() |
Дата | |
Msg-id | CAMbWs4_ka474zs2z7gfG0LiT5F61+HGAZqHYPeGFHKW5JwM4GQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Strange Bitmapset manipulation in DiscreteKnapsack() (David Rowley <dgrowleyml@gmail.com>) |
Ответы |
Re: Strange Bitmapset manipulation in DiscreteKnapsack()
|
Список | pgsql-hackers |
On Thu, Jan 18, 2024 at 8:35 AM David Rowley <dgrowleyml@gmail.com> wrote:
The functions's header comment mentions "The bitmapsets are all
pre-initialized with an unused high bit so that memory allocation is
done only once.".
Ah, I neglected to notice this when reviewing the v1 patch. I guess
it's implemented this way due to performance considerations, right?
it's implemented this way due to performance considerations, right?
I've attached a patch which adds bms_replace_members(). It's basically
like bms_copy() but attempts to reuse the member from another set. I
considered if the new function should be called bms_copy_inplace(),
but left it as bms_replace_members() for now.
Do you think we can use 'memcpy(a, b, BITMAPSET_SIZE(b->nwords))'
directly in the new bms_replace_members() instead of copying the
bitmapwords one by one, like:
- i = 0;
- do
- {
- a->words[i] = b->words[i];
- } while (++i < b->nwords);
-
- a->nwords = b->nwords;
+ memcpy(a, b, BITMAPSET_SIZE(b->nwords));
But I'm not sure if this is an improvement or not.
Thanks
Richard
directly in the new bms_replace_members() instead of copying the
bitmapwords one by one, like:
- i = 0;
- do
- {
- a->words[i] = b->words[i];
- } while (++i < b->nwords);
-
- a->nwords = b->nwords;
+ memcpy(a, b, BITMAPSET_SIZE(b->nwords));
But I'm not sure if this is an improvement or not.
Thanks
Richard
В списке pgsql-hackers по дате отправления: