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.31 by root, Tue Jul 29 02:00:55 2008 UTC vs.
Revision 1.38 by root, Thu Jan 1 21:15:12 2009 UTC

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 int alloc = sizeof (uint32_t) * 2 + len + 1;
44 45
45 shstr_alloc += sizeof (int) * 2 + len + 1; 46 shstr_alloc += alloc;
46 const char *v = (const char *) (2 + (int *)g_slice_alloc (sizeof (int) * 2 + len + 1)); 47 char *v = (char *)g_slice_alloc (alloc);
48 v += sizeof (uint32_t) * 2;
47 49
48 shstr::length (v) = len; 50 shstr::length (v) = len;
49 shstr::refcnt (v) = 1; 51 shstr::refcnt (v) = 1;
50 52
51 memcpy ((char *) v, s, len + 1); 53 memcpy (v, s, len + 1);
52 54
53 return v; 55 return v;
54} 56}
55 57
56static const char * 58shstr_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 59
66const char * 60const char *
67shstr::find (const char *s) 61shstr::find (const char *s)
68{ 62{
69 if (!s) 63 if (!s)
76 70
77const char * 71const char *
78shstr::intern (const char *s) 72shstr::intern (const char *s)
79{ 73{
80 if (!s) 74 if (!s)
81 return null; 75 return null ();
82 76
83 if (const char *found = find (s)) 77 if (const char *found = find (s))
84 { 78 {
85 ++refcnt (found); 79 ++refcnt (found);
86 return found; 80 return found;
125 const char *s = *o; 119 const char *s = *o;
126 120
127 ht.erase (o); 121 ht.erase (o);
128 122
129 //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); 123 //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; 124 int alloc = sizeof (uint32_t) * 2 + length (s) + 1;
131 g_slice_free1 (sizeof (int) * 2 + length (s) + 1, -2 + (int *) s); 125 shstr_alloc -= alloc;
126 g_slice_free1 (alloc, (void *)(s - sizeof (uint32_t) * 2));
132 } 127 }
133 else 128 else
134 ++i; 129 ++i;
135 } 130 }
136 131
137 curpos = *i; 132 curpos = *i;
138} 133}
139 134
140const shstr shstr_null;
141
142// declare these here to get correct initialisation order 135// declare these here to get correct initialisation order
143#define def(str) const shstr shstr_ ## str (# str); 136#define def2(id,str) const shstr id (str);
137#define def(id) def2(shstr_ ## id, # id)
144# include "shstrinc.h" 138# include "shstrinc.h"
145#undef def 139#undef def
140#undef def2
146 141
147shstr skill_names[NUM_SKILLS]; 142shstr skill_names[NUM_SKILLS];
148 143
149//TODO: this should of course not be here 144//TODO: this should of course not be here
150 145

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines