Replace magic numbers with constants in CollationSpecialPrimaries deserialization#8083
Conversation
|
This seems like a good change because it makes the code on main a little bit more parallel with the code on 2.1/2.2 |
…eserialization Defines NUM_PRIMARIES and COMPRESSIBLE_BYTES_LEN constants on CollationSpecialPrimaries and uses them in the custom Deserialize implementation to avoid magic numbers, making the deserialization logic self-documenting. Co-authored-by: Gemini <176961590+gemini-code-assist[bot]@users.noreply.github.com>
04bd62f to
95d5f95
Compare
| // `variant_count` isn't stable yet: | ||
| // https://github.com/rust-lang/rust/issues/73662 | ||
| .split_at_checked(MaxVariable::Currency as usize + 1) | ||
| .split_at_checked(CollationSpecialPrimaries::NUM_PRIMARIES) |
There was a problem hiding this comment.
issue: the "variant_count isn't stable yet" comment should be moved to the constant. it would also make more sense for the constant to live on MaxVariable, and be called something like VARIANT_COUNT, or fn variant_count().
| #[cfg(feature = "serde")] | ||
| impl CollationSpecialPrimaries<'_> { | ||
| /// The number of real special primaries (Space, Punctuation, Symbol, Currency). | ||
| pub(crate) const NUM_PRIMARIES: usize = MaxVariable::Currency as usize + 1; // 4 |
There was a problem hiding this comment.
I'd be happier with this way of variant counting if this lived next to the enum
| /// The length of the compressible bytes array (256 bits packed in 16 u16s). | ||
| pub(crate) const COMPRESSIBLE_BYTES_LEN: usize = 16; |
There was a problem hiding this comment.
| /// The length of the compressible bytes array (256 bits packed in 16 u16s). | |
| pub(crate) const COMPRESSIBLE_BYTES_LEN: usize = 16; | |
| /// The length of the compressible bytes array (256 bits packed in `u16`s). | |
| pub(crate) const COMPRESSIBLE_BYTES_LEN: usize = 256 / u16::BITS; |
There was a problem hiding this comment.
that said, the / u16::BITS could also be moved to the use site, with this just being 256, the number of bytes that are compressible, without worrying about how they are packed
See #8075
Defines
NUM_PRIMARIESandCOMPRESSIBLE_BYTES_LENconstants onCollationSpecialPrimariesand uses them in the customDeserializeimplementation to avoid magic numbers, making the deserialization logic self-documenting.This addresses reviewer feedback regarding magic numbers in the collation data handling.
🤖 This pull request was created by an AI agent working with @sffc.
Changelog
CollationSpecialPrimariesdeserialization.