From e924e8eb75da1f7e55c3cb717d8f9ddda6737df5 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Thu, 12 Feb 2026 21:12:46 -0500 Subject: [PATCH] Use dict lookup for charset and palette loading --- playscii/app.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/playscii/app.py b/playscii/app.py index ebd3a1b..ad803f6 100755 --- a/playscii/app.py +++ b/playscii/app.py @@ -409,6 +409,8 @@ class Application: self.onion_renderables_prev, self.onion_renderables_next = [], [] # lists of currently loaded character sets and palettes self.charsets, self.palettes = [], [] + self._charset_map = {} + self._palette_map = {} self.csl = CharacterSetLord(self) self.pl = PaletteLord(self) # set/create an active art @@ -739,12 +741,13 @@ class Application: # already loaded? base_charset_to_load = os.path.basename(charset_to_load) base_charset_to_load = os.path.splitext(base_charset_to_load)[0] - for charset in self.charsets: - if charset.base_filename == base_charset_to_load: - return charset + cached = self._charset_map.get(base_charset_to_load) + if cached is not None: + return cached new_charset = CharacterSet(self, charset_to_load, log) if new_charset.init_success: self.charsets.append(new_charset) + self._charset_map[base_charset_to_load] = new_charset return new_charset elif self.ui and self.ui.active_art: # if init failed (eg bad filename) return something safe @@ -753,12 +756,13 @@ class Application: def load_palette(self, palette_to_load, log=False): base_palette_to_load = os.path.basename(palette_to_load) base_palette_to_load = os.path.splitext(base_palette_to_load)[0] - for palette in self.palettes: - if palette.base_filename == base_palette_to_load: - return palette + cached = self._palette_map.get(base_palette_to_load) + if cached is not None: + return cached new_palette = Palette(self, palette_to_load, log) if new_palette.init_success: self.palettes.append(new_palette) + self._palette_map[base_palette_to_load] = new_palette return new_palette elif self.ui and self.ui.active_art: # if init failed (eg bad filename) return something safe