DIP 1019--Named Arguments Lite--Community Review Round 1
Atila Neves
atila.neves at gmail.com
Tue Feb 19 12:04:57 UTC 2019
On Monday, 18 February 2019 at 13:18:15 UTC, Rubn wrote:
> On Monday, 18 February 2019 at 10:17:32 UTC, Atila Neves wrote:
>> On Friday, 15 February 2019 at 17:43:52 UTC, 12345swordy wrote:
>>> On Friday, 15 February 2019 at 17:38:23 UTC, Francesco Mecca
>>> wrote:
>>>> On Friday, 15 February 2019 at 13:49:04 UTC, Atila Neves
>>>> wrote:
>>>>> [...]
>>>>
>>>> I think that the solution proposed by Atila is better for
>>>> the following reasons:
>>>> 1. it is a library solution
>>>> 2. allows both the user and the author of a library to
>>>> specify functions with named parameters
>>>> 3. it is very lightweight
>>>>
>>>> [...]
>>>
>>> You miss the other reason on why it is not enough: Compile
>>> time and run-time performance penalty.
>>> -Alex
>>
>> Run-time? I'd expect the call to inlined. It'll definitely
>> take longer to compile though, but I'm at a loss why named
>> parameters in the compiler are expected to be free.
>
> The compiler isn't some magic device, your implementation is
> not easily optimized out to have no runtime cost. Even LDC has
> trouble optimizing it, and forget about DMD.
>
> struct Foo {
> int[1024] value;
> }
<snip>
Good shout, thanks for bringing that up. I fixed this in version
0.0.2 (just pushed), and now both `callSlowFoo` and `callFastFoo`
below yield the exact same assembly with ldc, and the function
calls were inlined:
----------------------------------------------
import kwargs;
struct Foo {
int[1024] value;
}
void fastFoo(ref Foo faa) {
import core.stdc.stdio: printf;
foreach(int i, ref v; faa.value) {
printf("%d ", v);
}
printf("\n");
}
alias slowFoo = kwargify!fastFoo;
void callSlowFoo() {
Foo foo;
initFoo(foo);
slowFoo(foo);
}
void callFastFoo() {
Foo foo;
initFoo(foo);
fastFoo(foo);
}
void initFoo(ref Foo foo) {
foreach(int i, ref v; foo.value) {
v = i;
}
}
void main() {
callSlowFoo;
// callFastFoo; // it's the same!
}
----------------------------------------------
More information about the Digitalmars-d
mailing list