From 26f06f329864eedaa0487afabda294c097fd0c17 Mon Sep 17 00:00:00 2001 From: Chili Palmer Date: Sun, 21 Jun 2026 14:25:00 +0200 Subject: [PATCH] Optimize bounded atom lookups --- AUDIT.md | 2 ++ lib/bds/bounded_atoms.ex | 10 ++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/AUDIT.md b/AUDIT.md index 982cb87..0f2f8f1 100644 --- a/AUDIT.md +++ b/AUDIT.md @@ -38,6 +38,8 @@ after each item. - [x] `desktop/automation.ex` (verified keep: current module is an external-process automation harness; replacing it with `Desktop.Window` primitives would not be a local simplification) - [x] `desktop/shell_live/sidebar_events.ex` - [x] `MapUtils.attr/2` replacements +- [x] `ui/registry.ex` O(1) lookups (verified keep: compile-time caching would freeze localized labels) +- [x] `bounded_atoms.ex` O(1) allow-lists --- diff --git a/lib/bds/bounded_atoms.ex b/lib/bds/bounded_atoms.ex index 816de22..3cb0012 100644 --- a/lib/bds/bounded_atoms.ex +++ b/lib/bds/bounded_atoms.ex @@ -67,6 +67,8 @@ defmodule BDS.BoundedAtoms do %{id: id} -> [id] end) end) + @sidebar_view_ids Enum.map(Registry.sidebar_views(), & &1.id) + @editor_route_ids Enum.map(Registry.editor_routes(), & &1.id) def atom(value, allowed, fallback \\ nil) @@ -101,13 +103,9 @@ defmodule BDS.BoundedAtoms do Enum.find(allowed, fallback, &(Atom.to_string(&1) == value)) end - defp sidebar_views do - Enum.map(Registry.sidebar_views(), & &1.id) - end + defp sidebar_views, do: @sidebar_view_ids - defp editor_routes do - Enum.map(Registry.editor_routes(), & &1.id) - end + defp editor_routes, do: @editor_route_ids defp normalize_menu_kind("category-archive"), do: "category_archive" defp normalize_menu_kind(value), do: value