Skip to content

refactor(str): introduce LenAndHash abstraction#21244

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/04-09-refactor_str_introduce_lenandhash_abstraction
Apr 9, 2026
Merged

refactor(str): introduce LenAndHash abstraction#21244
graphite-app[bot] merged 1 commit intomainfrom
om/04-09-refactor_str_introduce_lenandhash_abstraction

Conversation

@overlookmotel
Copy link
Copy Markdown
Member

@overlookmotel overlookmotel commented Apr 9, 2026

Refactor to Ident.

len and hash fields are stored packed as a single u64 on 64-bit platforms, but as 2 separate u32s 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.

Copy link
Copy Markdown
Member Author

overlookmotel commented Apr 9, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of 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.

@github-actions github-actions Bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Apr 9, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 9, 2026

Merging this PR will not alter performance

✅ 48 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing om/04-09-refactor_str_introduce_lenandhash_abstraction (5e407e2) with om/04-09-refactor_str_move_display_impl_to_before_debug_impl (8cc87db)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@overlookmotel overlookmotel changed the base branch from om/04-08-refactor_str_import_traits_at_top_level to graphite-base/21244 April 9, 2026 10:53
@overlookmotel overlookmotel force-pushed the om/04-09-refactor_str_introduce_lenandhash_abstraction branch from 0c30698 to 403b9f6 Compare April 9, 2026 10:53
@overlookmotel overlookmotel changed the base branch from graphite-base/21244 to om/04-09-refactor_str_move_display_impl_to_before_debug_impl April 9, 2026 10:53
@overlookmotel overlookmotel self-assigned this Apr 9, 2026
@overlookmotel overlookmotel marked this pull request as ready for review April 9, 2026 10:57
Copilot AI review requested due to automatic review settings April 9, 2026 10:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 LenAndHash type with 64-bit (packed u64) and non-64-bit ({ len: u32, hash: u32 }) implementations.
  • Replace Ident’s platform-conditional len/hash fields with a single len_and_hash: LenAndHash, simplifying from_raw, length/hash accessors, Eq, and Hash.

Comment thread crates/oxc_str/src/ident.rs
@overlookmotel overlookmotel force-pushed the om/04-09-refactor_str_introduce_lenandhash_abstraction branch from 403b9f6 to fc493c6 Compare April 9, 2026 11:38
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented Apr 9, 2026

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.
@graphite-app graphite-app Bot force-pushed the om/04-09-refactor_str_move_display_impl_to_before_debug_impl branch from d56dc8e to 8cc87db Compare April 9, 2026 12:08
@graphite-app graphite-app Bot force-pushed the om/04-09-refactor_str_introduce_lenandhash_abstraction branch from fc493c6 to 5e407e2 Compare April 9, 2026 12:09
Base automatically changed from om/04-09-refactor_str_move_display_impl_to_before_debug_impl to main April 9, 2026 12:17
@graphite-app graphite-app Bot merged commit 5e407e2 into main Apr 9, 2026
36 checks passed
@graphite-app graphite-app Bot deleted the om/04-09-refactor_str_introduce_lenandhash_abstraction branch April 9, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants