… | |
… | |
44 | shstr::find (const char *s) |
44 | shstr::find (const char *s) |
45 | { |
45 | { |
46 | if (!s) |
46 | if (!s) |
47 | return s; |
47 | return s; |
48 | |
48 | |
49 | AUTODECL (i, ht.find (s)); |
49 | auto (i, ht.find (s)); |
50 | |
50 | |
51 | return i != ht.end ()? *i : 0; |
51 | return i != ht.end ()? *i : 0; |
52 | } |
52 | } |
53 | |
53 | |
54 | const char * |
54 | const char * |
… | |
… | |
73 | void |
73 | void |
74 | shstr::gc () |
74 | shstr::gc () |
75 | { |
75 | { |
76 | static const char *curpos; |
76 | static const char *curpos; |
77 | |
77 | |
78 | AUTODECL (i, curpos ? ht.find (curpos) : ht.begin ()); |
78 | auto (i, curpos ? ht.find (curpos) : ht.begin ()); |
79 | |
79 | |
80 | if (i == ht.end ()) |
80 | if (i == ht.end ()) |
81 | i = ht.begin (); |
81 | i = ht.begin (); |
82 | |
82 | |
83 | // go through all strings roughly once every 4 minutes |
83 | // go through all strings roughly once every 4 minutes |
… | |
… | |
92 | } |
92 | } |
93 | else if (!--n) |
93 | else if (!--n) |
94 | break; |
94 | break; |
95 | else if (!refcnt (*i)) |
95 | else if (!refcnt (*i)) |
96 | { |
96 | { |
97 | AUTODECL (o, i++); |
97 | auto (o, i++); |
98 | const char *s = *o; |
98 | const char *s = *o; |
99 | |
99 | |
100 | ht.erase (o); |
100 | ht.erase (o); |
101 | |
101 | |
102 | //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); |
102 | //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); |