https://issues.dlang.org/show_bug.cgi?id=13136
Issue ID: 13136 Summary: Optimize double lookup from if (v in assocArray) { return assocArray[v]; } Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: DMD Assignee: nob...@puremagic.com Reporter: marki...@umich.edu Andrei just informed me that I was wrong in assuming that the compiler would optimize out the double lookup performed by: if (v in assocArray) { return assocArray[v]; } And that I should instead use: if (auto valuePtr = v in assocArray) { return *valuePtr; } He suggested that I post an enhancement request to make these compile to equivalent code. Personally I'm a fan of the former approach as I find it to be a bit cleaner. --