[PR #7640] Introduce til::presorted_static_map #26959

Open
opened 2026-01-31 09:19:07 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/7640

State: closed
Merged: Yes


til::static_map can't be constexpr until we move to C++20.
It can't be constexpr because std::sort isn't constexpr until then.
This poses a problem: if we start using it and treating it like a map,
we'll incur a potentially high cost in static initialization in both
code size in .text and runtime.

This commit introduces presorted_static_map, which is static_map except
that it doesn't automatically sort its keys. That's the only difference.

At this point, it's just a maplike interface to a constant array of
pairs that does a binary search. It should be used for small tables that
are used infrequently enough as to not warrant their cost in code size
or initialization time. It should also be used for tables that aren't
going to be edited much by developers (like the color table in #7578.)

**Original Pull Request:** https://github.com/microsoft/terminal/pull/7640 **State:** closed **Merged:** Yes --- til::static_map can't be constexpr until we move to C++20. It can't be constexpr because std::sort isn't constexpr until then. This poses a problem: if we start using it and treating it like a map, we'll incur a potentially high cost in static initialization in both code size in .text and runtime. This commit introduces presorted_static_map, which is static_map except that it doesn't automatically sort its keys. That's the only difference. At this point, it's just a maplike interface to a constant array of pairs that does a binary search. It should be used for small tables that are used infrequently enough as to not warrant their cost in code size or initialization time. It should also be used for tables that aren't going to be edited much by developers (like the color table in #7578.)
claunia added the pull-request label 2026-01-31 09:19:07 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26959