From c2030384f0bc51d5fce467abd4c34012b1a51100 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 20 Nov 2024 12:10:07 +0300 Subject: [PATCH] More optimal retrival of components: 1) using refs 2) using EcsPool.GetOrDefault(..) --- tpl/bind_ecslite.twig | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tpl/bind_ecslite.twig b/tpl/bind_ecslite.twig index 3ace8b5..c61abd7 100644 --- a/tpl/bind_ecslite.twig +++ b/tpl/bind_ecslite.twig @@ -120,10 +120,11 @@ {%- endif ~%} { var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>(); - if(pool.Has(id)) + ref var comp = ref pool.GetOrDefault(id, out bool exists); + if(exists) { dv = Val.New(frm.vm); - var v = pool.Get(id).{{f.name}}; + var v = comp.{{f.name}}; {{ bhl_bind.native2val(f.type, 'v', 'dv') }}; } else @@ -160,13 +161,14 @@ var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>(); - if(pool.Has(id)) + ref var comp = ref pool.GetOrDefault(id, out bool exists); + if(exists) { {%~ if m.returntype %} var return_val = {%- endif ~%} - pool.Get(id).{{m.name}}( + comp.{{m.name}}( {%- for arg in m.args ~%} __{{arg.name}}{% if not loop.last %},{% endif %} {%- endfor ~%} );