A bit optimizing array assignment codegen
Publish PHP Package / docker (push) Successful in 7s Details

This commit is contained in:
Pavel Shevaev 2024-07-12 14:05:36 +03:00
parent 02412f515d
commit 7c97dd78ed
1 changed files with 10 additions and 8 deletions

View File

@ -407,15 +407,16 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
{%- endif -%}
{%- if type is instanceof('\\mtgArrType') -%}
var _arr_type = (ArrayTypeSymbol){{value}}.type;
int _native_before_count = 0;
var _src_arr_type = (ArrayTypeSymbol){{value}}.type;
int _dst_before_count = 0;
int _src_arr_count = _src_arr_type.ArrCount({{value}});
{%- if type == 'any[]'-%}
{%~ if type == 'any[]'-%}
{{native}} = ValList.New(frm.vm);
{%~ else ~%}
try
{
_native_before_count = {{native}}.Count;
_dst_before_count = {{native}}.Count;
}
catch(NullReferenceException)
{
@ -423,17 +424,18 @@ Script_{{o.name|norm_name}}.Method_{{m.name}}.ReturnValue(frm, stack
}
{%~ endif -%}
for(int i=0;i<_arr_type.ArrCount({{value}});++i)
for(int i=0;i<_src_arr_count;++i)
{
var _arr_item = _arr_type.ArrGetAt({{value}}, i);
var _arr_item = _src_arr_type.ArrGetAt({{value}}, i);
{#TODO: get rid of replace hack below#}
{{('var ' ~ _self.val2native(type.value, '_arr_item', 'tmp'))|replace({'tmp = tmp' : '', 'var var' : 'var'})}};
if(i < _native_before_count)
if(i < _dst_before_count)
{{native}}[i] = tmp;
else
{{native}}.Add(tmp);
}
while({{native}}.Count > _arr_type.ArrCount({{value}}))
while({{native}}.Count > _src_arr_count)
{{native}}.RemoveAt({{native}}.Count-1);
{%- endif -%}