ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/shstr.C
(Generate patch)

Comparing deliantra/server/common/shstr.C (file contents):
Revision 1.40 by root, Wed Nov 4 00:02:48 2009 UTC vs.
Revision 1.41 by root, Tue Nov 10 00:01:31 2009 UTC

36typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *> > HT; 36typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *> > HT;
37 37
38static HT ht; 38static HT ht;
39static int next_gc; 39static int next_gc;
40 40
41#define NUM_INT 3
42
41static const char * 43static const char *
42makevec (const char *s) 44makevec (const char *s)
43{ 45{
44 int len = strlen (s); 46 int len = strlen (s);
45 int alloc = sizeof (uint32_t) * 2 + len + 1; 47 int alloc = sizeof (uint32_t) * NUM_INT + len + 1;
46 48
47 shstr_alloc += alloc; 49 shstr_alloc += alloc;
48 char *v = (char *)g_slice_alloc (alloc); 50 char *v = (char *)g_slice_alloc (alloc);
49 v += sizeof (uint32_t) * 2; 51 v += sizeof (uint32_t) * NUM_INT;
50 52
53 shstr::hash (v) = strhsh (s);
51 shstr::length (v) = len; 54 shstr::length (v) = len;
52 shstr::refcnt (v) = 1; 55 shstr::refcnt (v) = 1;
53 56
54 memcpy (v, s, len + 1); 57 memcpy (v, s, len + 1);
55 58
56 return v; 59 return v;
57} 60}
58 61
59shstr_vec<sizeof "(null)"> shstr_tmp::nullvec = { 0, 0xffffffff, "(null)" }; 62shstr_vec<sizeof "(null)"> shstr_tmp::nullvec = { STRHSH_NULL, 0, 0xffffffff, "(null)" };
60 63
61const char * 64const char *
62shstr::find (const char *s) 65shstr::find (const char *s)
63{ 66{
64 if (!s) 67 if (!s)
120 const char *s = *o; 123 const char *s = *o;
121 124
122 ht.erase (o); 125 ht.erase (o);
123 126
124 //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); 127 //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s));
125 int alloc = sizeof (uint32_t) * 2 + length (s) + 1; 128 int alloc = sizeof (uint32_t) * NUM_INT + length (s) + 1;
126 shstr_alloc -= alloc; 129 shstr_alloc -= alloc;
127 g_slice_free1 (alloc, (void *)(s - sizeof (uint32_t) * 2)); 130 g_slice_free1 (alloc, (void *)(s - sizeof (uint32_t) * NUM_INT));
128 } 131 }
129 else 132 else
130 ++i; 133 ++i;
131 } 134 }
132 135

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines