More pure optimizations
Ary Borenszweig
ary at esperanto.org.ar
Wed Jun 3 18:28:12 PDT 2009
bearophile escribió:
> Once that optimization is in place, the reading access to associative arrays too can be marked as "pure" so the in the following code h["bar"] is seen as a loop invariant, and computed only once before the loop:
>
> import std.c.stdio: printf;
>
> int foo(int[string] h) {
> int x;
> for (int i; i < 100; i++)
> x += h["bar"];
> return x;
> }
>
> void main() {
> printf("%d\n", foo(["bar": 42]));
> }
What if a different thread modifies h in between the loop?
More information about the Digitalmars-d
mailing list