From 7e6a9f85578e2940877a61e1af01f94cb2606221 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Sun, 26 Jul 2026 12:50:33 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20(core):=20Clave=20`&'stati?= =?UTF-8?q?c=20str`=20en=20RegionComponents?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/theme/regions.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/theme/regions.rs b/src/core/theme/regions.rs index 515337f3..f6ac2e18 100644 --- a/src/core/theme/regions.rs +++ b/src/core/theme/regions.rs @@ -9,11 +9,14 @@ use std::sync::{Arc, LazyLock}; // Mapea cada nombre de región con su lista de prototipos de componentes. // +// La clave es `&'static str` (lo que ya devuelve `RegionName::name()`) en lugar de `String`. No +// hace falta reservar en el heap una copia de un dato que ya vive de forma estática. +// // Se comparten como `Arc`. El prototipo no se clona al registrarse ni al ensamblar // la región (sólo se clona el `Arc`, barato). En cambio, sí se realiza un clonado del componente en // `Child::render()`, cuando cada petición necesita su propia copia mutable para pasar por `setup()` // desde un estado inicial limpio. -type RegionComponents = HashMap>>; +type RegionComponents = HashMap<&'static str, Vec>>; // Regiones globales con prototipos asociados a un tema específico. static THEME_REGIONS: LazyLock>> = @@ -27,7 +30,7 @@ static COMMON_REGIONS: LazyLock> = // Contenedor interno de componentes agrupados por región. #[derive(AutoDefault)] -pub(crate) struct ChildrenInRegions(HashMap); +pub(crate) struct ChildrenInRegions(HashMap<&'static str, Children>); impl ChildrenInRegions { pub fn with(region: RegionRef, child: Child) -> Self { @@ -42,7 +45,7 @@ impl ChildrenInRegions { region.alter_child(child); } else { let children = Children::new().with_child(child); - self.0.insert(region_name.to_owned(), children); + self.0.insert(region_name, children); } self } @@ -164,7 +167,7 @@ impl InRegion { .write() .entry(theme.type_id()) .or_default() - .entry((*region).name().to_owned()) + .entry((*region).name()) .or_default() .push(proto); } @@ -176,7 +179,7 @@ impl InRegion { fn add_to_common(region: RegionRef, proto: Arc) { COMMON_REGIONS .write() - .entry(region.name().to_owned()) + .entry(region.name()) .or_default() .push(proto); }