-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: optimize tag color resolution #42
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,9 @@ export const TAG_COLORS: TagColor[] = [ | |
| { name: "pink", bg: "bg-pink-100 dark:bg-pink-950", text: "text-pink-700 dark:text-pink-300", border: "border-pink-200 dark:border-pink-900", activeBg: "bg-pink-600 dark:bg-pink-500", activeText: "text-white", activeBorder: "border-pink-700 dark:border-pink-400" }, | ||
| ]; | ||
|
|
||
| // O(1) optimized lookup map for constant tag color data | ||
| const TAG_COLORS_MAP = new Map(TAG_COLORS.map(c => [c.name, c])); | ||
|
|
||
| const STORAGE_KEY = "opencitation:tag-colors"; | ||
| const CHANGE_EVENT = "opencitation:tag-colors-changed"; | ||
|
|
||
|
|
@@ -56,7 +59,8 @@ function writeMap(map: Record<string, string>) { | |
| export function resolveTagColor(tag: string, map: Record<string, string>): TagColor { | ||
| const named = map[tag]; | ||
| if (named) { | ||
| const found = TAG_COLORS.find((c) => c.name === named); | ||
| // ⚡ Bolt: Replace O(N) array .find() with O(1) Map lookup | ||
| const found = TAG_COLORS_MAP.get(named); | ||
| if (found) return found; | ||
|
Comment on lines
61
to
64
|
||
| } | ||
| return hashColor(tag); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The inline comment includes branding/emoji ("⚡ Bolt") but doesn’t add much beyond what the code already shows. Consider replacing it with a neutral, durable explanation (or removing it) to keep comments from becoming stale/noisy over time.