Files
zed/crates/gpui_util
froQ d551a5fd50 Fix hashing of signed zero in Pixels, RenderGlyphParams and DocumentColor (#67346)
## Summary

`Pixels`, `RenderGlyphParams` and `DocumentColor` implement `Eq`, but
their
`PartialEq` compares `f32` numerically while their `Hash` hashes
`f32::to_bits()`. `0.0` and `-0.0` compare equal and hash differently,
so a
lookup with an equal key can miss. `RenderGlyphParams` is the live glyph
raster cache, and `DocumentColor` is the key of the `HashSet` that
deduplicates language server colours.

Closes #67334

All three `Hash` impls now drop the sign of zero before hashing, through
one `gpui_util::canonical_float_bits` helper.
`Pixels` ordering now treats `0.0` and `-0.0` as equal too, as it did
before 1f94463ce2 switched it to `total_cmp`.
Without that, the wrapped-line cache shares one entry for both zero wrap
widths while wrapping still told them apart, so the wrapped height
depended on which width was requested first.
Equality is untouched, and ordering changes only between `0.0` and
`-0.0`: `-0.0 < 0.0` is now false.

## Testing

One regression test per type, written before the fix. They fail on the
parent
commit and pass with it.

- `cargo test -p gpui --test eq_hash`, 2 passed
- `cargo test -p project --lib document_color`, 1 passed
- `cargo test -p project --lib`, 114 passed
- `cargo test -p gpui --lib --all-features`, 540 passed, 1 failed
  (`bench_context` timing test, passes when run alone)
- `cargo clippy -p gpui -p project --all-targets --all-features --
--deny warnings`, clean
- `test_wrap_ignores_the_sign_of_a_zero_wrap_width_in_the_cache`
compares a warm and a cold wrapped-line cache; it fails without the
`Ord` change and passes with it
- `cargo test -p gpui --features test-support --lib --tests`, 458 + 3
passed
- `cargo test -p editor --lib`, 1235 passed

No UI change.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [ ] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- N/A
- [GPUI] Fixed `Pixels` and `RenderGlyphParams` hashing and `Pixels`
ordering so values that compare equal also hash and order the same

---------

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2026-11-23 10:56:34 +00:00
..
…