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.32 by root, Wed Dec 31 17:35:37 2008 UTC vs.
Revision 1.33 by root, Wed Dec 31 18:07:41 2008 UTC

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 (unsigned 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 (unsigned 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_tmp::length (s) = 0;
61 //shstr ::refcnt (s) = 0xffffffff; // useful for debugging
62 return s;
63}
64
65const char *shstr_tmp::null = makenull ();
66 57
67const char * 58const char *
68shstr::find (const char *s) 59shstr::find (const char *s)
69{ 60{
70 if (!s) 61 if (!s)
77 68
78const char * 69const char *
79shstr::intern (const char *s) 70shstr::intern (const char *s)
80{ 71{
81 if (!s) 72 if (!s)
82 return null; 73 return null ();
83 74
84 if (const char *found = find (s)) 75 if (const char *found = find (s))
85 { 76 {
86 ++refcnt (found); 77 ++refcnt (found);
87 return found; 78 return found;
126 const char *s = *o; 117 const char *s = *o;
127 118
128 ht.erase (o); 119 ht.erase (o);
129 120
130 //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));
131 shstr_alloc -= sizeof (unsigned int) * 2 + length (s) + 1; 122 shstr_alloc -= sizeof (uint32_t) * 2 + length (s) + 1;
132 g_slice_free1 (sizeof (unsigned int) * 2 + length (s) + 1, -2 + (int *) s); 123 g_slice_free1 (sizeof (uint32_t) * 2 + length (s) + 1, -2 + (int *) s);
133 } 124 }
134 else 125 else
135 ++i; 126 ++i;
136 } 127 }
137 128
138 curpos = *i; 129 curpos = *i;
139} 130}
140
141const shstr shstr_null;
142 131
143// declare these here to get correct initialisation order 132// declare these here to get correct initialisation order
144#define def(str) const shstr shstr_ ## str (# str); 133#define def(str) const shstr shstr_ ## str (# str);
145# include "shstrinc.h" 134# include "shstrinc.h"
146#undef def 135#undef def

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines