digitalmars.D.bugs - [Issue 17938] New: Detect immutable variadic arguments
- d-bugmail puremagic.com (66/66) Oct 26 2017 https://issues.dlang.org/show_bug.cgi?id=17938
https://issues.dlang.org/show_bug.cgi?id=17938 Issue ID: 17938 Summary: Detect immutable variadic arguments Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: performance Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: dfj1esp02 sneakemail.com --- void f(in string[] a...); void g() { f("a","b","c"); } void h() { static immutable string[3] b=["a","b","c"]; f(b); } --- void example.g(): push %rbp mov %rsp,%rbp sub $0x40,%rsp mov %rbx,-0x38(%rbp) mov $0x0,%ecx mov $0x1,%eax mov %rax,-0x30(%rbp) mov %rcx,-0x28(%rbp) mov $0x0,%edx mov $0x1,%ebx mov %rbx,-0x20(%rbp) mov %rdx,-0x18(%rbp) mov $0x0,%ecx mov $0x1,%esi mov %rsi,-0x10(%rbp) mov %rcx,-0x8(%rbp) lea -0x30(%rbp),%rdx mov $0x3,%edi mov %rdx,%rsi xor %eax,%eax callq 55 <void example.g()+0x55> mov -0x38(%rbp),%rbx leaveq retq void example.h(): push %rbp mov %rsp,%rbp mov $0x0,%edx mov $0x3,%edi mov %rdx,%rsi xor %eax,%eax callq 18 <void example.h()+0x18> pop %rbp retq --- The calls are equivalent, but function h looks more efficient and has less code generated. Function g amounts to 24 instructions and 91 bytes, h - to 9 instructions and 32 bytes. --
Oct 26 2017