D perfomance

random random at spaml.de
Wed Apr 29 10:46:57 UTC 2020


On Wednesday, 29 April 2020 at 10:36:59 UTC, IGotD- wrote:
> I'm incompetent so I would just write:
>
> int test(int* x, int* y) {
>      *x = 0;
>      *y = 1;
>      return 0;
> }

Ok in this simple case it's obvius.
For a real world example look at the source for strcmp():
https://code.woboq.org/userspace/glibc/string/strcmp.c.html

The trick is to load the value in a variable. The compiler can't 
optimize multiple pointer reads from the same pointer because the 
content could already be changed by an other pointer. restrict 
solves that, but if you now what is happening and why you can 
solve that by hand.




More information about the Digitalmars-d mailing list