[Issue 13136] New: Optimize double lookup from if (v in assocArray) { return assocArray[v]; }

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Jul 15 13:03:21 PDT 2014


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 at puremagic.com
          Reporter: markisaa at 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.

--


More information about the Digitalmars-d-bugs mailing list