digitalmars.D.bugs - [Issue 13136] New: Optimize double lookup from if (v in assocArray)
- via Digitalmars-d-bugs (23/23) Jul 15 2014 https://issues.dlang.org/show_bug.cgi?id=13136
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: nobody puremagic.com Reporter: markisaa 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. --
Jul 15 2014