From a38bfff992053a7e52a5f2f790fa16a65e8cdb5c Mon Sep 17 00:00:00 2001 From: "remy.baranx@gmail.com" Date: Wed, 26 Feb 2025 10:41:35 +0000 Subject: [PATCH] small improvement of model layout code generation --- crates/dojo/lang/src/attribute_macros/model.rs | 11 +++++++++++ .../src/attribute_macros/patches/model.patch.cairo | 9 +-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/dojo/lang/src/attribute_macros/model.rs b/crates/dojo/lang/src/attribute_macros/model.rs index e29b5327b3..a644eb6bba 100644 --- a/crates/dojo/lang/src/attribute_macros/model.rs +++ b/crates/dojo/lang/src/attribute_macros/model.rs @@ -228,12 +228,23 @@ impl DojoModel { "dojo::storage::DojoStore".to_string() }; + let model_layout = if use_legacy_storage { + format!( + "dojo::meta::layout::build_legacy_layout( + dojo::meta::Introspect::<{model_type}>::layout() + )" + ) + } else { + format!("dojo::meta::Introspect::<{model_type}>::layout()") + }; + diagnostics.extend(derive_diagnostics); let node = RewriteNode::interpolate_patched( MODEL_CODE_PATCH, &UnorderedHashMap::from([ ("model_type".to_string(), RewriteNode::Text(model_type.clone())), + ("model_layout".to_string(), RewriteNode::Text(model_layout.clone())), ("serialized_keys".to_string(), RewriteNode::new_modified(serialized_keys)), ("serialized_values".to_string(), RewriteNode::new_modified(serialized_values)), ("deserialized_values".to_string(), RewriteNode::new_modified(deserialized_values)), diff --git a/crates/dojo/lang/src/attribute_macros/patches/model.patch.cairo b/crates/dojo/lang/src/attribute_macros/patches/model.patch.cairo index 5f47433f80..5d3d5afbb4 100644 --- a/crates/dojo/lang/src/attribute_macros/patches/model.patch.cairo +++ b/crates/dojo/lang/src/attribute_macros/patches/model.patch.cairo @@ -26,14 +26,7 @@ pub mod m_$model_type$_definition { #[inline(always)] fn layout() -> dojo::meta::Layout { - if $use_legacy_storage$ { - dojo::meta::layout::build_legacy_layout( - dojo::meta::Introspect::<$model_type$>::layout() - ) - } - else { - dojo::meta::Introspect::<$model_type$>::layout() - } + $model_layout$ } #[inline(always)]