• Welcome to Theos PowerBasic Museum 2017.

News:

Attachments are only available to registered users.
Please register using your full, real name.

Main Menu

(Optimization) Don't use ISFALSE if you can use (=0)

Started by Theo Gottwald, January 02, 2007, 09:39:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

Whats wrong with:


' Example Message handler loop
WHILE GetMessage( Msg, BYVAL %NULL, 0, 0 )
    IF ISFALSE TranslateMDISysAccel( hWndClient, Msg ) THEN
      IF ISFALSE TranslateAccelerator( hWndMain, hAccel, Msg ) THEN
        IF ISFALSE IsDialogMessage( hFind, Msg ) THEN
          IF ISFALSE IsDialogMessage( hWndMain, Msg ) THEN
            TranslateMessage Msg
            DispatchMessage Msg
          END IF
        END IF
      END IF
    END IF
  WEND


In fact it works fine.
But when you take a look into DisASM, it looks quite diffrent.

We take out one of the lines and take a closer look what the compiler is doing with the "ISFALSE" compared to "(...=0)".



IF ISFALSE(TranslateMDISysAccel( hWndClient, Msg )) THEN   

' becomes this:

4088C6 8D9D5CFFFFFF           LEA EBX, DWORD PTR [EBP+FFFFFF5C]
4088CC 53                     PUSH EBX
4088CD FF3548D54000           PUSH DWORD PTR [0040D548]
4088D3 FF1558F44000           CALL DWORD PTR [0040F458]
4088D9 E85D390000             CALL L40C23B
4088DE E80D1E0000             CALL L40A6F0
4088E3 D9E4                   FTST
4088E5 DFE0                   FNSTSW AX
4088E7 9E                     SAHF
4088E8 DDD8                   FSTPST, ST(0)
4088EA 66B8FFFF               MOV AX, WORD FFFF
4088EE 7402                   JZ  SHORT L4088F2
4088F0 6640                   INC  AX
4088F2 E8EE1D0000             CALL L40A6E5
4088F7 D9E4                   FTST
4088F9 DFE0                   FNSTSW AX
4088FB 9E                     SAHF
4088FC DDD8                   FSTPST, ST(0)
4088FE 0F849E000000           JZ  L4089A2





IF (TranslateMDISysAccel( hWndClient, Msg )=0) THEN   

' becomes

4088C6 6A00                   PUSH BYTE 00
4088C8 8D9D5CFFFFFF           LEA EBX, DWORD PTR [EBP+FFFFFF5C]
4088CE 53                     PUSH EBX
4088CF FF3548D54000           PUSH DWORD PTR [0040D548]
4088D5 FF1558F44000           CALL DWORD PTR [0040F458]
4088DB E83B390000             CALL L40C21B
4088E0 8F45D4                 POP DWORD PTR [EBP-2C]
4088E3 3B45D4                 CMP EAX, DWORD PTR [EBP-2C]
4088E6 0F859E000000           JNZ L40898A


Which is a lot cheaper!

Therefore let me recommend to NOT use ISFALSE wherever you can use (=0).