Bill Baxter:
>Or this avoids a double lookup if the symbol is present:<
In LDC both forms (and several other ones, if the usage of the pointer is
local, and it doesn't get passed away) get simplified to the same single lookup
code :-) (but not in DMD).
So much that you may even think of "in" to
Bill Baxter wrote:
> You query presence of a key in an AA using 'in'
>
> if (id in symtab) {
> Symbol sym = symtab[id];
> ...
> } else {
> ..
> }
>
> Or this avoids a double lookup if the symbol is present:
>
> Symbol* pSym = id in symtab;
> if (pSym !is null) {
>
On Fri, Oct 16, 2009 at 4:11 PM, Manfred_Nowak wrote:
> Bill Baxter wrote:
>
>> Symbol* pSym = id in symtab;
>
> shouldn't the compiler sort this out?
I'm not really sure what you mean, but I think the answer is that
there's a difference between an unset entry and one that's set to
null.
--bb
Bill Baxter wrote:
> Symbol* pSym = id in symtab;
shouldn't the compiler sort this out?
-manfred
Bill Baxter Wrote:
> You query presence of a key in an AA using 'in'
Thank you Bill .. esp. the tip to avoid double lookup.
JJ
You query presence of a key in an AA using 'in'
if (id in symtab) {
Symbol sym = symtab[id];
...
} else {
..
}
Or this avoids a double lookup if the symbol is present:
Symbol* pSym = id in symtab;
if (pSym !is null) {
Symbol sym = *pSym;
...
} else {
What's wrong with this simple symbol table class?
class Symbol
{
private char[] id;
private static Symbol[char[]] symtab;
private this( string id) {
this.id = id;
}
static Symbol opCall( char[] id) {
Symbol sym = symtab[id]; // *** ArrayBoundsError here
if (sym