C++ can be faster as ASM, it depend of your compiler
Code:
CMsg::CMs>/$ 55 PUSH EBP
10001017 |. 8BEC MOV EBP,ESP
10001019 |. 83EC 08 SUB ESP,8
1000101C |. C745 F8 CCCCC>MOV [LOCAL.2],CCCCCCCC
10001023 |. C745 FC CCCCC>MOV [LOCAL.1],CCCCCCCC
1000102A |. 894D F8 MOV [LOCAL.2],ECX
1000102D |. C745 FC 30B00>MOV [LOCAL.1],MuMsg.1001B030 ; ASCII "Msg error"
10001034 |. 6A 34 PUSH 34 ; /n = 34 (52.)
10001036 |. 6A 00 PUSH 0 ; |c = 00
10001038 |. 8B45 F8 MOV EAX,[LOCAL.2] ; |
1000103B |. 05 24000200 ADD EAX,20024 ; |
10001040 |. 50 PUSH EAX ; |s
10001041 |. E8 0A080000 CALL MuMsg.memset ; \memset
10001046 |. 83C4 0C ADD ESP,0C
10001049 |. 8B4D F8 MOV ECX,[LOCAL.2]
1000104C |. C701 00000000 MOV DWORD PTR DS:[ECX],0
10001052 |. 8B55 FC MOV EDX,[LOCAL.1]
10001055 |. 52 PUSH EDX ; /src
10001056 |. 8B45 F8 MOV EAX,[LOCAL.2] ; |
10001059 |. 05 24000200 ADD EAX,20024 ; |
1000105E |. 50 PUSH EAX ; |dest
1000105F |. E8 FC060000 CALL MuMsg.strcpy ; \strcpy
10001064 |. 83C4 08 ADD ESP,8
10001067 |. 8B45 F8 MOV EAX,[LOCAL.2]
1000106A |. 83C4 08 ADD ESP,8
1000106D |. 3BEC CMP EBP,ESP
1000106F |. E8 3C080000 CALL MuMsg._chkesp
10001074 |. 8BE5 MOV ESP,EBP
10001076 |. 5D POP EBP
10001077 \. C3 RETN
Now Optimized , note that there aren't calls
Code:
CMsg::CMs>/$ 8BD1 MOV EDX,ECX
10001022 |. 53 PUSH EBX
10001023 |. 56 PUSH ESI
10001024 |. 57 PUSH EDI
10001025 |. 8D9A 24000200 LEA EBX,DWORD PTR DS:[EDX+20024]
1000102B |. B9 0D000000 MOV ECX,0D
10001030 |. 33C0 XOR EAX,EAX
10001032 |. 8BFB MOV EDI,EBX
10001034 |. F3:AB REP STOS DWORD PTR ES:[EDI]
10001036 |. BF 30800010 MOV EDI,MuMsg.10008030 ; ASCII "Msg error"
1000103B |. 83C9 FF OR ECX,FFFFFFFF
1000103E |. 8902 MOV DWORD PTR DS:[EDX],EAX
10001040 |. F2:AE REPNE SCAS BYTE PTR ES:[EDI]
10001042 |. F7D1 NOT ECX
10001044 |. 2BF9 SUB EDI,ECX
10001046 |. 8BC1 MOV EAX,ECX
10001048 |. 8BF7 MOV ESI,EDI
1000104A |. 8BFB MOV EDI,EBX
1000104C |. C1E9 02 SHR ECX,2
1000104F |. F3:A5 REP MOVS DWORD PTR ES:[EDI],DWORD PTR DS>
10001051 |. 8BC8 MOV ECX,EAX
10001053 |. 8BC2 MOV EAX,EDX
10001055 |. 83E1 03 AND ECX,3
10001058 |. F3:A4 REP MOVS BYTE PTR ES:[EDI],BYTE PTR DS:[>
1000105A |. 5F POP EDI
1000105B |. 5E POP ESI
1000105C |. 5B POP EBX
1000105D \. C3 RETN
Original
Code:
CMsg::CMsg() // Correct
{
char * szMessageError ="Msg error";
memset(&this->m_szMuMsgError , 0, sizeof(this->m_szMuMsgError ) );
this->m_ListInit = 0;
strcpy(this->m_szMuMsgError , szMessageError);
}
Now i MUST remark that less lines don't means Better perfomance, Registers in ASM were made for increase the speed, thats why many c++ compilers use it on its routines, playing with code like INC DWORD PTR DS[XXXXXXX] is for reduce the code , playing with INC EAX is related with Speed, however ASM can be faster i think
PD: some new compilers also Add an special feature related with Calling procedures, they avoid the classic PUSH , instead of that they reserve a space for the stack, adding the ESP value, and then they use the MOV instruction , this also increase even more the speed, at first look, this should look more "heavy", but it is faster