… | |
… | |
39 | |
39 | |
40 | static const char * |
40 | static const char * |
41 | makevec (const char *s) |
41 | makevec (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 (uint32_t) * 2 + len + 1; |
46 | shstr_alloc += alloc; |
46 | const char *v = (const char *) (2 + (int *)g_slice_alloc (sizeof (uint32_t) * 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 | |
56 | shstr_vec<sizeof "(null)"> shstr_tmp::nullvec = { 0, 0xffffffff, "(null)" }; |
58 | shstr_vec<sizeof "(null)"> shstr_tmp::nullvec = { 0, 0xffffffff, "(null)" }; |
… | |
… | |
117 | const char *s = *o; |
119 | const char *s = *o; |
118 | |
120 | |
119 | ht.erase (o); |
121 | ht.erase (o); |
120 | |
122 | |
121 | //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)); |
122 | shstr_alloc -= sizeof (uint32_t) * 2 + length (s) + 1; |
124 | int alloc = sizeof (uint32_t) * 2 + length (s) + 1; |
123 | g_slice_free1 (sizeof (uint32_t) * 2 + length (s) + 1, -2 + (int *) s); |
125 | shstr_alloc -= alloc; |
|
|
126 | g_slice_free1 (alloc, (void *)(s - sizeof (uint32_t) * 2)); |
124 | } |
127 | } |
125 | else |
128 | else |
126 | ++i; |
129 | ++i; |
127 | } |
130 | } |
128 | |
131 | |
129 | curpos = *i; |
132 | curpos = *i; |
130 | } |
133 | } |
131 | |
134 | |
132 | // declare these here to get correct initialisation order |
135 | // declare these here to get correct initialisation order |
133 | #define def2(id,str) const shstr shstr_ ## id (str); |
136 | #define def2(id,str) const shstr id (str); |
134 | #define def(id) def2(id, # id) |
137 | #define def(id) def2(shstr_ ## id, # id) |
135 | # include "shstrinc.h" |
138 | # include "shstrinc.h" |
136 | #undef def |
139 | #undef def |
137 | #undef def2 |
140 | #undef def2 |
138 | |
141 | |
139 | shstr skill_names[NUM_SKILLS]; |
142 | shstr skill_names[NUM_SKILLS]; |