Skip to content

Make BitArray a little constexpr-friendly#2335

Open
abacabadabacaba wants to merge 1 commit into
ton-blockchain:testnetfrom
abacabadabacaba:bitarray-constexpr
Open

Make BitArray a little constexpr-friendly#2335
abacabadabacaba wants to merge 1 commit into
ton-blockchain:testnetfrom
abacabadabacaba:bitarray-constexpr

Conversation

@abacabadabacaba

Copy link
Copy Markdown
Contributor

No description provided.

@github-actions

Copy link
Copy Markdown

No issues found.

@DanShaders DanShaders left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removes operator< for n % 8 != 0 case and the explicit defaulted copy constructor. Don't think this matters much though.

@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown
  • crypto/common/bitstring.h:513: operator=(ConstBitPtr) now assigns through BitArray(from). For non-byte-aligned n, that constructor leaves the unused bits in the last byte uninitialized, then copies the whole std::array into *this. Previously assignment copied only n bits into existing storage, so a zeroed tail stayed zero. This can make as_slice()/as_array() expose nondeterministic tail bits after BitArray<15> x = BitArray<15>::zero(); x = ptr;. Keep the direct bits_memcpy assignment path or zero-initialize the temporary storage first.

  • crypto/common/bitstring.h:574: non-byte-aligned BitArrays lost relational ordering. The old operator< worked for every n, but the new <=> is only declared for n % 8 == 0, and compare() is not used for rewritten relational operators. Existing or downstream code using BitArray<15>/BitArray<267> in ordered comparisons or ordered containers will no longer have the same API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants