Juha Manninen (gmail) escreveu:
A new Lazarus review :
http://delphimax.wordpress.com/2010/09/13/freepascal-and-lazarus-success-or-
failure/

has this comment about Lazarus source:
---
Abundant use of the Exit() command instead of nesting code in If/then/else. It has been proven (last time in Delphi Informant Magazine) that allowing a method to nest itself out makes faster code. It is also easier to read and study. Exit should of course be used (it must be used in many situations) but prudently.
---

Does nesting really create faster code?


If i understand right what you mean by nesting, the produced code is equal at least in my simple test. See attached.

I dont know for more complex situations

Luiz

program template;
{$Mode ObjFpc}

procedure DoIt;
begin
  WriteLn('DoIt');
end;  

procedure UseExit(i: Integer);
begin
  if i = 0 then Exit;
  DoIt;
end;  

procedure DontUseExit(i: Integer);
begin
  if i <> 0 then
    DoIt;  
end;

begin //Main 
  UseExit(1);
  DontUseExit(1); 
end.
        .file "asmExit.pas"

.section .text

.section .text
        .balign 4
        .balign 4
# [asmExit.pas]
# [5] begin
.globl  P$TEMPLATE_DOIT
P$TEMPLATE_DOIT:
# Temps allocated between ebp-4 and ebp+0
        pushl   %ebp
        movl    %esp,%ebp
        subl    $4,%esp
        movl    %ebx,-4(%ebp)
# [6] WriteLn('DoIt');
        call    fpc_get_output
        movl    %eax,%ebx
        movl    $_$PROGRAM$_L10,%ecx
        movl    %ebx,%edx
        movl    $0,%eax
        call    fpc_write_text_shortstr
        call    FPC_IOCHECK
        movl    %ebx,%eax
        call    fpc_writeln_end
        call    FPC_IOCHECK
# [7] end;
        movl    -4(%ebp),%ebx
        leave
        ret

.section .text
        .balign 4
        .balign 4
# [10] begin
.globl  P$TEMPLATE_USEEXIT$LONGINT
P$TEMPLATE_USEEXIT$LONGINT:
# Temps allocated between ebp-4 and ebp-4
        pushl   %ebp
        movl    %esp,%ebp
        subl    $4,%esp
# Var i located at ebp-4
        movl    %eax,-4(%ebp)
# [11] if i = 0 then Exit;
        testl   %eax,%eax
        je      .L22
# [12] DoIt;
        call    P$TEMPLATE_DOIT
# [13] DoIt;
        call    P$TEMPLATE_DOIT
# [14] DoIt;
        call    P$TEMPLATE_DOIT
# [15] DoIt;
        call    P$TEMPLATE_DOIT
# [16] DoIt;
        call    P$TEMPLATE_DOIT
# [17] DoIt;
        call    P$TEMPLATE_DOIT
# [18] DoIt;
        call    P$TEMPLATE_DOIT
# [19] DoIt;
        call    P$TEMPLATE_DOIT
# [20] DoIt;
        call    P$TEMPLATE_DOIT
# [21] DoIt;
        call    P$TEMPLATE_DOIT
.L22:
# [22] end;
        leave
        ret

.section .text
        .balign 4
        .balign 4
# [25] begin
.globl  P$TEMPLATE_DONTUSEEXIT$LONGINT
P$TEMPLATE_DONTUSEEXIT$LONGINT:
# Temps allocated between ebp-4 and ebp-4
        pushl   %ebp
        movl    %esp,%ebp
        subl    $4,%esp
# Var i located at ebp-4
        movl    %eax,-4(%ebp)
# [26] if i <> 0 then
        testl   %eax,%eax
        je      .L34
# [28] DoIt;
        call    P$TEMPLATE_DOIT
# [29] DoIt;
        call    P$TEMPLATE_DOIT
# [30] DoIt;
        call    P$TEMPLATE_DOIT
# [31] DoIt;
        call    P$TEMPLATE_DOIT
# [32] DoIt;
        call    P$TEMPLATE_DOIT
# [33] DoIt;
        call    P$TEMPLATE_DOIT
# [34] DoIt;
        call    P$TEMPLATE_DOIT
# [35] DoIt;
        call    P$TEMPLATE_DOIT
# [36] DoIt;
        call    P$TEMPLATE_DOIT
# [37] DoIt;
        call    P$TEMPLATE_DOIT
.L34:
# [39] end;
        leave
        ret

.section .text
        .balign 4
        .balign 4
# [41] begin //Main
.globl  PASCALMAIN
PASCALMAIN:
.globl  _main
_main:
# Temps allocated between ebp+0 and ebp+0
        pushl   %ebp
        movl    %esp,%ebp
        call    FPC_INITIALIZEUNITS
# [42] UseExit(1);
        movl    $1,%eax
        call    P$TEMPLATE_USEEXIT$LONGINT
# [43] DontUseExit(1);
        movl    $1,%eax
        call    P$TEMPLATE_DONTUSEEXIT$LONGINT
# [44] end.
        call    FPC_DO_EXIT
        leave
        ret
        .balign 4

.section .data
        .ascii  "FPC 2.0.4 [2006/08/21] for i386 - Win32"
        .balign 16
        .balign 16
.globl  THREADVARLIST_P$TEMPLATE
THREADVARLIST_P$TEMPLATE:
        .long   0
        .balign 4
.globl  FPC_THREADVARTABLES
FPC_THREADVARTABLES:
        .long   3
        .long   THREADVARLIST_SYSTEM
        .long   THREADVARLIST_OBJPAS
        .long   THREADVARLIST_P$TEMPLATE
        .balign 4
.globl  FPC_RESOURCESTRINGTABLES
FPC_RESOURCESTRINGTABLES:
        .long   0
        .balign 4
.globl  INITFINAL
INITFINAL:
        .long   2,0
        .long   INIT$_SYSTEM
        .long   FINALIZE$_SYSTEM
        .long   INIT$_OBJPAS
        .long   FINALIZE$_OBJPAS

.section .data
        .balign 4
.globl  __stklen
__stklen:
        .long   262144

.section .data
        .balign 4
.globl  __heapsize
__heapsize:
        .long   0

.section .data

.section .data
        .balign 4
.globl  _$PROGRAM$_L10
_$PROGRAM$_L10:
        .ascii  "\004DoIt\000"

.section .data

.section .data

.section .bss

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to