Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-07

optimization of "inline" open array constants

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dmitry Boyarintsev

Hello,

Here's the code:

procedure dump(const a: array of string);
var
  i : integer;
begin
  for i:=0 to length(a)-1 do
    writeln(a[i]);
end;
const
  fast : array [0..2] of string = ('aa','bb','cc');
begin
  dump(['a','b','c']);
  dump(fast);
end.

The first call to dump(), where the array is passed as "inline" declaration, consists of building of an open array with string constants:

movl $_$PROGRAM$_Ld4,%eax
movl %eax,-12(%ebp)
movl $_$PROGRAM$_Ld5,%eax
movl %eax,-8(%ebp)
movl $_$PROGRAM$_Ld6,%eax
movl %eax,-4(%ebp)
leal -12(%ebp),%eax
movl $2,%edx
call P$PROGRAM_DUMP$array_of_ANSISTRING

the second call, is however just passing a reference to the constant of the open array ("fast")

movl $TC_P$PROGRAM_FAST,%eax
movl $2,%edx
call P$PROGRAM_DUMP$array_of_ANSISTRING

Question: would it be reasonable for the compiler to turn an inline declaration of ['a','b','c'], into a constant implicitly? That would save some instructions to make a call

  dump(['a','b','c']);

is there an optimization switch for that already?

thanks,
Dmitry

Reply by email

Dmitry Boyarintsev
to Jonas Maebe

Thank you! That answers all my questions

Jonas Maebe wrote 15 lines
On 23/07/14 18:09, Dmitry Boyarintsev wrote: > Question: would it be reasonable for the compiler to turn an inline > declaration of ['a','b','c'], into a constant implicitly? > There's already a feature request for it: http://bugs.freepascal.org/ view.php?id=23565 Jonas _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply by email