Using "in" with associative arrays and then indexing them (efficiency)

Matej Nanut matejnanut at
Tue Jan 3 02:52:13 PST 2012

Hello everyone,

I would like to know whether

        if (symbol in symbols)
                return symbols[symbol];

is any less efficient than

        auto tmp = symbol in symbols;
        if (tmp !is null)
                return *tmp;

Without optimisation, it looks like the first example
searches for `symbol' twice.


More information about the Digitalmars-d-learn mailing list