refactor(str): introduce LenAndHash abstraction#21244
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Merging this PR will not alter performance
Comparing Footnotes
|
4071989 to
d56dc8e
Compare
0c30698 to
403b9f6
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors oxc_str::Ident by introducing an internal LenAndHash abstraction to encapsulate the platform-specific representation of identifier length and precomputed hash, reducing #[cfg] duplication while preserving the optimized layout (including 12-byte Ident on 32-bit targets).
Changes:
- Introduce a
LenAndHashtype with 64-bit (packedu64) and non-64-bit ({ len: u32, hash: u32 }) implementations. - Replace
Ident’s platform-conditionallen/hashfields with a singlelen_and_hash: LenAndHash, simplifyingfrom_raw, length/hash accessors,Eq, andHash.
403b9f6 to
fc493c6
Compare
Merge activity
|
Refactor to `Ident`. `len` and `hash` fields are stored packed as a single `u64` on 64-bit platforms, but as 2 separate `u32`s on 32-bit. This reduces size of `Ident` to 12 bytes on 32-bit. Introduce a `LenAndHash` struct which abstracts away this platform difference, so that all other methods can be written once, rather than having to have separate `#[cfg(target_pointer_width = "64")]` and `#[cfg(not(target_pointer_width = "64"))]` implementations, which need to be kept in sync with each other.
d56dc8e to
8cc87db
Compare
fc493c6 to
5e407e2
Compare

Refactor to
Ident.lenandhashfields are stored packed as a singleu64on 64-bit platforms, but as 2 separateu32s on 32-bit. This reduces size ofIdentto 12 bytes on 32-bit.Introduce a
LenAndHashstruct which abstracts away this platform difference, so that all other methods can be written once, rather than having to have separate#[cfg(target_pointer_width = "64")]and#[cfg(not(target_pointer_width = "64"))]implementations, which need to be kept in sync with each other.