On Thu, Jan 18, 2024 at 8:35 AM David Rowley <[email protected]> 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?
> 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