objective c - @autorelease Pool and Loops (for, while, do) Syntax -
clang
allows following loop syntax:
for (...) @autorelease { ... } while (...) @autorelease { ... } @autorelease { ... } while (...);
i haven't found documentation on syntax far (apple doesn't use syntax in guides, @ least no in guides introducing @autorelease
construct), reasonable assume 3 statement above equivalent 3 statements below:
for (...) { @autorelease { ... } } while (...) { @autorelease { ... } } { @autorelease { ... } } while (...);
since expect them (going standard c syntax rules), yet i'm not entirely sure if that's case. "special syntax", autorelease pool not renewed every loop iteration.
both syntax same
-(void)afunc { int i=0; for(;i<5;) @autoreleasepool { ++i; } } -(void)bfunc { int i=0; for(;i<5;) { @autoreleasepool { ++i; } } }
assembly code
"-[appdelegate afunc]": ## @"\01-[appdelegate afunc]" .cfi_startproc lfunc_begin0: .loc 1 12 0 ## /users/parag/desktop/test/test/appdelegate.m:12:0 ## bb#0: pushq %rbp ltmp2: .cfi_def_cfa_offset 16 ltmp3: .cfi_offset %rbp, -16 movq %rsp, %rbp ltmp4: .cfi_def_cfa_register %rbp subq $32, %rsp movq %rdi, -8(%rbp) movq %rsi, -16(%rbp) .loc 1 14 12 prologue_end ## /users/parag/desktop/test/test/appdelegate.m:14:12 ltmp5: movl $0, -20(%rbp) lbb0_1: ## =>this inner loop header: depth=1 .loc 1 15 5 ## /users/parag/desktop/test/test/appdelegate.m:15:5 ltmp6: cmpl $5, -20(%rbp) jge lbb0_3 ## bb#2: ## in loop: header=bb0_1 depth=1 .loc 1 16 26 ## /users/parag/desktop/test/test/appdelegate.m:16:26 ltmp7: callq _objc_autoreleasepoolpush .loc 1 17 13 ## /users/parag/desktop/test/test/appdelegate.m:17:13 movl -20(%rbp), %ecx addl $1, %ecx movl %ecx, -20(%rbp) .loc 1 18 9 ## /users/parag/desktop/test/test/appdelegate.m:18:9 movq %rax, %rdi callq _objc_autoreleasepoolpop jmp lbb0_1 ltmp8: lbb0_3: .loc 1 19 1 ## /users/parag/desktop/test/test/appdelegate.m:19:1 addq $32, %rsp popq %rbp ret ltmp9: lfunc_end0: .file 2 "/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/macosx10.8.sdk/system/library/frameworks/foundation.framework/headers/nsobject.h" .file 3 "/users/parag/desktop/test/test/appdelegate.h" .cfi_endproc .align 4, 0x90 "-[appdelegate bfunc]": ## @"\01-[appdelegate bfunc]" .cfi_startproc lfunc_begin1: .loc 1 20 0 ## /users/parag/desktop/test/test/appdelegate.m:20:0 ## bb#0: pushq %rbp ltmp12: .cfi_def_cfa_offset 16 ltmp13: .cfi_offset %rbp, -16 movq %rsp, %rbp ltmp14: .cfi_def_cfa_register %rbp subq $32, %rsp movq %rdi, -8(%rbp) movq %rsi, -16(%rbp) .loc 1 22 12 prologue_end ## /users/parag/desktop/test/test/appdelegate.m:22:12 ltmp15: movl $0, -20(%rbp) lbb1_1: ## =>this inner loop header: depth=1 .loc 1 23 5 ## /users/parag/desktop/test/test/appdelegate.m:23:5 ltmp16: cmpl $5, -20(%rbp) jge lbb1_3 ## bb#2: ## in loop: header=bb1_1 depth=1 .loc 1 25 26 ## /users/parag/desktop/test/test/appdelegate.m:25:26 ltmp17: callq _objc_autoreleasepoolpush .loc 1 26 14 ## /users/parag/desktop/test/test/appdelegate.m:26:14 movl -20(%rbp), %ecx addl $1, %ecx movl %ecx, -20(%rbp) .loc 1 27 9 ## /users/parag/desktop/test/test/appdelegate.m:27:9 movq %rax, %rdi callq _objc_autoreleasepoolpop ltmp18: .loc 1 28 5 ## /users/parag/desktop/test/test/appdelegate.m:28:5 jmp lbb1_1 ltmp19: lbb1_3: .loc 1 29 1 ## /users/parag/desktop/test/test/appdelegate.m:29:1 addq $32, %rsp popq %rbp ret ltmp20: lfunc_end1:
Comments
Post a Comment