Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Merge configurations in lexicographic order #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

SRugina
Copy link

@SRugina SRugina commented Mar 7, 2025

A for..in loop on a BinaryHeap is not sorted,
see https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.iter
so the old code, whilst presumably intended to be sorted, was actually
iterating with a random order.

Collecting as a Vec then sorting is simpler and more efficient since
read_dir depends on FS and can be in ascending order which degrades
each insertion from O(1) to O(log(n)), amortised, for BinaryHeap,
see https://doc.rust-lang.org/alloc/collections/binary_heap/struct.BinaryHeap.html#time-complexity-3

That random order was causing downstream bugs:

as, e.g. inside a flatpak, /etc/fonts/conf.d/05-flatpak-fontpath.conf
features a <reset-dirs /> that would then hide the flatpak-specific
<dir>s like /run/host/fonts in /etc/fonts/conf.d/50-flatppk.conf
if the 05- file gets merged after the 50- file.

SRugina added 3 commits March 7, 2025 04:13
A `for..in` loop on a `BinaryHeap` is not sorted,
see https://doc.rust-lang.org/std/collections/struct.BinaryHeap.html#method.iter
so the old code, whilst presumably _intended_ to be sorted, was actually
iterating with a random order.

Collecting as a `Vec` then sorting is simpler and more efficient since
`read_dir` depends on FS and can be in ascending order which degrades
each insertion from `O(1)` to `O(log(n))`, amortised, for `BinaryHeap`,
see https://doc.rust-lang.org/alloc/collections/binary_heap/struct.BinaryHeap.html#time-complexity-3

That random order was causing downstream bugs:

- zed-industries/zed#18982
- zed-industries/zed#22676
- flathub/dev.lapce.lapce#50
- RazrFalcon/fontdb#78

as, e.g. inside a flatpak, `/etc/fonts/conf.d/05-flatpak-fontpath.conf`
features a `<reset-dirs />` that would then hide the flatpak-specific
`<dir>`s like `/run/host/fonts` in `/etc/fonts/conf.d/50-flatppk.conf`
if the `05-` file gets merged after the `50-` file.
`Number(1)` and `Number(1.0)` were not asserting as equal, so `Double`
instances in the JSON files had to be updated to all be floats.
`ResetDirs` should work both within one config (removing `<dir>`s before
it), and across configs when they're merged in lexicographic order.
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.

1 participant