Преглед на файлове

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 преди 12 години
родител
ревизия
b81f746e05
променени са 2 файла, в които са добавени 7 реда и са изтрити 10 реда
  1. 6 1
      compiler/ncginl.pas
  2. 1 9
      compiler/ninl.pas

+ 6 - 1
compiler/ncginl.pas

@@ -294,7 +294,7 @@ implementation
          end
          end
         else
         else
          begin
          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);
            hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
            current_asmdata.getjumplabel(lengthlab);
            current_asmdata.getjumplabel(lengthlab);
            cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_EQ,0,left.location.register,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;
              end;
            if is_widestring(left.resultdef) then
            if is_widestring(left.resultdef) then
              cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SHR,OS_INT,1,hregister);
              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);
            cg.a_label(current_asmdata.CurrAsmList,lengthlab);
            location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
            location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
            location.register:=hregister;
            location.register:=hregister;

+ 1 - 9
compiler/ninl.pas

@@ -2740,15 +2740,7 @@ implementation
                                cordconstnode.create(1,sinttype,false));
                                cordconstnode.create(1,sinttype,false));
                            exit;
                            exit;
                          end
                          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
                         else
                           begin
                           begin
                             { will be handled in simplify }
                             { will be handled in simplify }