Mercurial > projects > ddmd
diff dmd/StringTable.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | af724d3510d7 |
children | 0622fff7810a |
line wrap: on
line diff
--- a/dmd/StringTable.d Sun Oct 10 10:38:55 2010 +0400 +++ b/dmd/StringTable.d Sun Oct 17 07:42:00 2010 +0400 @@ -12,14 +12,91 @@ import std.stdio; -class StringTable +struct StringTable { + Object[string] table; + + ~this() + { + foreach (k, v; table) { + delete v; + } + } + + Object* lookup(string s) + { + return s in table; + } + + Object* insert(string s) + { + auto value = s in table; + if (value !is null) { + return null; + } + + table[s] = null; + + return s in table; + } + + Object* update(string s) + { + auto value = s in table; + if (value !is null) { + return value; + } + + table[s] = null; + + return s in table; + } + + /* + StringValue* lookup(string s) + { + if (auto p = s in table) { + return *p; + } + + return null; + } + + StringValue* insert(string s) + { + if (auto p = s in table) { + return null; + } + + auto value = new StringValue(); + value.lstring.string_ = s; + table[s] = value; + + return value; + } + + StringValue* update(string s) + { + if (auto p = s in table) { + return *p; + } + + auto value = new StringValue(); + value.lstring.string_ = s; + table[s] = value; + + return value; + } + */ + + /* void** table; uint count; uint tabledim; this(uint size = 37) { + register(); table = cast(void**)GC.calloc(size * (void*).sizeof); memset(table, 0, size * (void*).sizeof); tabledim = size; @@ -63,7 +140,7 @@ return &se.value; } - + void insertCopy(StringEntry* proto) { StringEntry** pse = search(proto.value.lstring.string_); @@ -140,4 +217,5 @@ //printf("\treturn %p, %p\n",se, (*se)); return se; } + */ }