Quellcode durchsuchen

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 -
masta vor 12 Jahren
Ursprung
Commit
b81f746e05
2 geänderte Dateien mit 7 neuen und 10 gelöschten Zeilen
  1. 6 1
      compiler/ncginl.pas
  2. 1 9
      compiler/ninl.pas

+ 6 - 1
compiler/ncginl.pas

@@ -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;

+ 1 - 9
compiler/ninl.pas

@@ -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 }