comparison 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
comparison
equal deleted inserted replaced
177:1475fd394c9e 178:e3afd1303184
10 10
11 import core.memory; 11 import core.memory;
12 12
13 import std.stdio; 13 import std.stdio;
14 14
15 class StringTable 15 struct StringTable
16 { 16 {
17 Object[string] table;
18
19 ~this()
20 {
21 foreach (k, v; table) {
22 delete v;
23 }
24 }
25
26 Object* lookup(string s)
27 {
28 return s in table;
29 }
30
31 Object* insert(string s)
32 {
33 auto value = s in table;
34 if (value !is null) {
35 return null;
36 }
37
38 table[s] = null;
39
40 return s in table;
41 }
42
43 Object* update(string s)
44 {
45 auto value = s in table;
46 if (value !is null) {
47 return value;
48 }
49
50 table[s] = null;
51
52 return s in table;
53 }
54
55 /*
56 StringValue* lookup(string s)
57 {
58 if (auto p = s in table) {
59 return *p;
60 }
61
62 return null;
63 }
64
65 StringValue* insert(string s)
66 {
67 if (auto p = s in table) {
68 return null;
69 }
70
71 auto value = new StringValue();
72 value.lstring.string_ = s;
73 table[s] = value;
74
75 return value;
76 }
77
78 StringValue* update(string s)
79 {
80 if (auto p = s in table) {
81 return *p;
82 }
83
84 auto value = new StringValue();
85 value.lstring.string_ = s;
86 table[s] = value;
87
88 return value;
89 }
90 */
91
92 /*
17 void** table; 93 void** table;
18 uint count; 94 uint count;
19 uint tabledim; 95 uint tabledim;
20 96
21 this(uint size = 37) 97 this(uint size = 37)
22 { 98 {
99 register();
23 table = cast(void**)GC.calloc(size * (void*).sizeof); 100 table = cast(void**)GC.calloc(size * (void*).sizeof);
24 memset(table, 0, size * (void*).sizeof); 101 memset(table, 0, size * (void*).sizeof);
25 tabledim = size; 102 tabledim = size;
26 count = 0; 103 count = 0;
27 } 104 }
61 ++count; 138 ++count;
62 } 139 }
63 140
64 return &se.value; 141 return &se.value;
65 } 142 }
66 143
67 void insertCopy(StringEntry* proto) 144 void insertCopy(StringEntry* proto)
68 { 145 {
69 StringEntry** pse = search(proto.value.lstring.string_); 146 StringEntry** pse = search(proto.value.lstring.string_);
70 StringEntry* se = *pse; 147 StringEntry* se = *pse;
71 if (se is null) 148 if (se is null)
138 } 215 }
139 216
140 //printf("\treturn %p, %p\n",se, (*se)); 217 //printf("\treturn %p, %p\n",se, (*se));
141 return se; 218 return se;
142 } 219 }
220 */
143 } 221 }