[fpc-devel] temp strings for constants,and double dec_ref
Martin
lazarus at mfriebe.de
Fri Aug 24 12:46:50 CEST 2012
While I am at it.
Using an open array
DebugLn(['abc']);
The string constant, is passed directly to the method (no temporary vars
used)
but ( procedure DebugLn(const s: string = ''); inline; overload; )
DebugLn('abc');
generates the code at the end of the mail. It first makes a copy of the
string (the pointer, not the content) to a temp var.
And not only this there is an unnecessary fpc_ansistr_decr_ref
- in 2.6 there are 2 calls to fpc_ansistr_decr_ref
- in trunc it is fpc_ansistr_decr_ref and fpc_ansistr_assign (the latter
including a further call to the former)
That is I have no problem, that the temp var (if it has to be there at
all) is dec-refed once. After all, if there was more pascal code before,
the temp may be in use....
But since fpc_ansistr_assign, does dec_red the target, why needs there
to be another explicit call?
UNIT1$_$TFORM1_$__$$_FORMCREATE$TOBJECT:
.Lc6:
# Temps allocated between ebp-56 and ebp-8
.Ll7:
# [42] begin
pushl %ebp
.Lc8:
.Lc9:
movl %esp,%ebp
.Lc10:
subl $56,%esp
movl %ebx,-56(%ebp)
# Var Sender located at ebp-4
# Var $self located at ebp-8
movl %eax,-8(%ebp)
movl %edx,-4(%ebp)
.Ll8:
movl $0,-52(%ebp)
.Ll9:
# [44] DebugLn('abc');
leal -20(%ebp),%ecx
leal -44(%ebp),%edx
movl $1,%eax
call FPC_PUSHEXCEPTADDR
call FPC_SETJMP
pushl %eax
testl %eax,%eax
jne .Lj18
leal -52(%ebp),%eax
call fpc_ansistr_decr_ref
movl $_$UNIT1$_Ld1,%edx
leal -52(%ebp),%eax
call fpc_ansistr_assign
call LAZLOGGERBASE_$$_GETDEBUGLOGGER$$TLAZLOGGER
movl %eax,%ebx
movl -52(%ebp),%edx
movl %ebx,%eax
call LAZLOGGERBASE$_$TLAZLOGGER_$__$$_DEBUGLN$ANSISTRING
.Lj18:
call FPC_POPADDRSTACK
.Ll10:
# [45] end;
leal -52(%ebp),%eax
call fpc_ansistr_decr_ref
popl %eax
testl %eax,%eax
je .Lj19
call FPC_RERAISE
.Lj19:
movl -56(%ebp),%ebx
leave
ret
.Lc7:
.Lt2:
.Ll11:
# End asmlist al_procedures
More information about the fpc-devel
mailing list