Inline Length(DynamicArray)

Up until now a helperfunction was called at runtime. This change inlines
the whole code in the same way Length(AnsiString) works. As dynamic
arrays do not record their length but their highest index, an additional
"OP_ADD" is this case.

git-svn-id: trunk@25227 -
This commit is contained in:
masta 2013-08-07 22:07:08 +00:00
parent 0d9211b3bc
commit b81f746e05
2 changed files with 7 additions and 10 deletions

View File

@ -294,7 +294,7 @@ implementation
end
else
begin
{ length in ansi/wide strings is at offset -sizeof(pint) }
{ length in ansi/wide strings and high in dynamic arrays is at offset -sizeof(pint) }
hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
current_asmdata.getjumplabel(lengthlab);
cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_EQ,0,left.location.register,lengthlab);
@ -312,6 +312,11 @@ implementation
end;
if is_widestring(left.resultdef) then
cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SHR,OS_INT,1,hregister);
{ Dynamic arrays do not have their length attached but their maximum index }
if is_dynamic_array(left.resultdef) then
cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_ADD,OS_INT,1,hregister);
cg.a_label(current_asmdata.CurrAsmList,lengthlab);
location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
location.register:=hregister;

View File

@ -2740,15 +2740,7 @@ implementation
cordconstnode.create(1,sinttype,false));
exit;
end
else if is_dynamic_array(left.resultdef) then
begin
hp := ccallparanode.create(ctypeconvnode.create_internal(left,voidpointertype),nil);
result := ccallnode.createintern('fpc_dynarray_length',hp);
{ make sure the left node doesn't get disposed, since it's }
{ reused in the new node (JM) }
left:=nil;
exit;
end
{ Length() for dynamic arrays is inlined }
else
begin
{ will be handled in simplify }