for(unsigned int i=0;i<(strlen(szBuffer)+2);i++) |
|
| Most compilers will optimize it to only be evaluated once, though. |
| Most compilers will optimize it to only be evaluated once, though. |
|
|
|
|
f2()
.L9:
movsbl (%rbx), %esi
movl $cout, %edi
incq %rbx
call operator<<(std::ostream&, char)
cmpq $.LC0+6, %rbx
jne .L9
movl $cout, %edi
call endl(ostream&)
decl %ebp
je .L7
.L8:
movl $.LC0, %ebx
jmp .L9
.L7: |
|
|
f2()
..B3.5:
movb $0, %bpl
..B3.6:
movzbl %bpl, %edx
movl $cout, %edi
movsbl .L_2__STRING.0(%rdx), %esi
call operator<<(std::ostream&, char)
..B3.7:
incb %bpl
cmpb $6, %bpl
jb ..B3.6
..B3.8:
movl $cout, %edi
movl $endl(ostream&), %esi
call operator<<(ostream& (*)(ostream&))
..B3.9:
incb %bl
cmpb $6, %bl
jl ..B3.5 |
std::endl
|
|
| In my head I think that f2() is better that f1() function because in f1() every round the second for loop must calculates strlen(szBuffer) but in f2 is been already calculated and assingned to a local variable am I right? |
|
|
f2()
__L1410:
addi r28,r0,0
lwz r4,T.122.NO_SYMBOL(RTOC)
addi r29,r4,-1
ori r0,r0,0x0000
__L1420:
addi r0,r0,6
lbz r4,1(r29)
addi r29,r29,1
lwz r3,T.238.std::cout(RTOC)
ori r0,r0,0x0000
bl .std::operator(std::ostream&,char)
ori r0,r0,0x0000
addi r28,r28,1
addi r0,r0,6
cmpl 0,0,r28,r0
bc BO_IF,CR0_LT,__L1420
lwz r3,T.238.cout(RTOC)
lwz r0,0(r31)
lwz r11,8(r31)
mtspr CTR,r0
lwz RTOC,4(r31)
bcctrl BO_ALWAYS,CR0_LT
lwz RTOC,20(SP)
addi r30,r30,1
cmpi 0,0,r30,6
bc BO_IF,CR0_LT,__L1410 |
|
|
strncat(szBuffer, /*...*/) inside the loop. (However getting too worried about optimization in that case is probably example of premature optimization)