RFR: 8300487: Store cardinality as a field in BitSet
fabioromano1
duke at openjdk.org
Wed Jan 18 11:21:54 UTC 2023
On Wed, 11 Jan 2023 15:33:47 GMT, Claes Redestad <redestad at openjdk.org> wrote:
>> I agree with the fact that is less intrusive, but certainly not potentially quicker, since the complete recalculation of cardinality requires linear time in the value of wordsInUse
>
> A perhaps slightly less racy way would be to only read and write from `words` once:
>
> final long newValue = words[wordIndex] ^ bitMask;
> cardinality += (newValue & bitMask) != 0 ? 1 : -1;
> words[wordIndex] = newValue;
>
> .. but the fact remains that `BitSet` is not thread-safe, so I think we shouldn't complicate things to avoid or eliminate potential races. (Using a local might help the compiler to avoid the back-to-back array read, but probably doesn't matter)
I think the same of @cl4es.
-------------
PR: https://git.openjdk.org/jdk/pull/11837
More information about the core-libs-dev
mailing list