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.29 by root, Fri Apr 11 21:09:52 2008 UTC vs.
Revision 1.36 by root, Thu Jan 1 11:41:17 2009 UTC

30 30
31#include "global.h" 31#include "global.h"
32 32
33size_t shstr_alloc; 33size_t shstr_alloc;
34 34
35typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *>, true> HT; 35typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *> > HT;
36 36
37static HT ht; 37static HT ht;
38static int next_gc; 38static int next_gc;
39 39
40static const char * 40static const char *
41makevec (const char *s) 41makevec (const char *s)
42{ 42{
43 int len = strlen (s); 43 int len = strlen (s);
44 44
45 shstr_alloc += sizeof (int) * 2 + len + 1; 45 shstr_alloc += sizeof (uint32_t) * 2 + len + 1;
46 const char *v = (const char *) (2 + (int *)g_slice_alloc (sizeof (int) * 2 + len + 1)); 46 const char *v = (const char *) (2 + (int *)g_slice_alloc (sizeof (uint32_t) * 2 + len + 1));
47 47
48 shstr::length (v) = len; 48 shstr::length (v) = len;
49 shstr::refcnt (v) = 1; 49 shstr::refcnt (v) = 1;
50 50
51 memcpy ((char *) v, s, len + 1); 51 memcpy ((char *) v, s, len + 1);
52 52
53 return v; 53 return v;
54} 54}
55 55
56static const char * 56shstr_vec<sizeof "(null)"> shstr_tmp::nullvec = { 0, 0xffffffff, "(null)" };
57makenull ()
58{
59 const char *s = makevec ("(null)");
60 shstr::length (s) = 0;
61 return s;
62}
63
64const char *shstr::null = makenull ();
65 57
66const char * 58const char *
67shstr::find (const char *s) 59shstr::find (const char *s)
68{ 60{
69 if (!s) 61 if (!s)
76 68
77const char * 69const char *
78shstr::intern (const char *s) 70shstr::intern (const char *s)
79{ 71{
80 if (!s) 72 if (!s)
81 return null; 73 return null ();
82 74
83 if (const char *found = find (s)) 75 if (const char *found = find (s))
84 { 76 {
85 ++refcnt (found); 77 ++refcnt (found);
86 return found; 78 return found;
125 const char *s = *o; 117 const char *s = *o;
126 118
127 ht.erase (o); 119 ht.erase (o);
128 120
129 //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); 121 //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s));
130 shstr_alloc -= sizeof (int) * 2 + length (s) + 1; 122 shstr_alloc -= sizeof (uint32_t) * 2 + length (s) + 1;
131 g_slice_free1 (sizeof (int) * 2 + length (s) + 1, -2 + (int *) s); 123 g_slice_free1 (sizeof (uint32_t) * 2 + length (s) + 1, -2 + (int *) s);
132 } 124 }
133 else 125 else
134 ++i; 126 ++i;
135 } 127 }
136 128
137 curpos = *i; 129 curpos = *i;
138} 130}
139 131
140// declare these here to get correct initialisation order 132// declare these here to get correct initialisation order
141#define def(str) const shstr shstr_ ## str (# str); 133#define def2(id,str) const shstr shstr_ ## id (str);
134#define def(id) def2(id, # id)
142# include "shstrinc.h" 135# include "shstrinc.h"
143#undef def 136#undef def
137#undef def2
144 138
145shstr skill_names[NUM_SKILLS]; 139shstr skill_names[NUM_SKILLS];
146 140
147//TODO: this should of course not be here 141//TODO: this should of course not be here
148 142

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines