… | |
… | |
28 | #include <glib.h> |
28 | #include <glib.h> |
29 | #include <tr1/unordered_set> |
29 | #include <tr1/unordered_set> |
30 | |
30 | |
31 | #include "global.h" |
31 | #include "global.h" |
32 | |
32 | |
|
|
33 | size_t shstr_alloc; |
|
|
34 | |
33 | typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *>, true> HT; |
35 | typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *>, true> HT; |
34 | |
36 | |
35 | static HT ht; |
37 | static HT ht; |
36 | |
38 | |
37 | static const char * |
39 | static const char * |
38 | makevec (const char *s) |
40 | makevec (const char *s) |
39 | { |
41 | { |
40 | int len = strlen (s); |
42 | int len = strlen (s); |
41 | |
43 | |
|
|
44 | shstr_alloc += sizeof (int) * 2 + len + 1; |
42 | const char *v = (const char *) (2 + (int *)g_slice_alloc (sizeof (int) * 2 + len + 1)); |
45 | const char *v = (const char *) (2 + (int *)g_slice_alloc (sizeof (int) * 2 + len + 1)); |
43 | |
46 | |
44 | shstr::length (v) = len; |
47 | shstr::length (v) = len; |
45 | shstr::refcnt (v) = 1; |
48 | shstr::refcnt (v) = 1; |
46 | |
49 | |
… | |
… | |
117 | const char *s = *o; |
120 | const char *s = *o; |
118 | |
121 | |
119 | ht.erase (o); |
122 | ht.erase (o); |
120 | |
123 | |
121 | //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); |
124 | //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); |
|
|
125 | shstr_alloc -= sizeof (int) * 2 + length (s) + 1; |
122 | g_slice_free1 (sizeof (int) * 2 + length (s) + 1, -2 + (int *) s); |
126 | g_slice_free1 (sizeof (int) * 2 + length (s) + 1, -2 + (int *) s); |
123 | } |
127 | } |
124 | else |
128 | else |
125 | ++i; |
129 | ++i; |
126 | } |
130 | } |
127 | |
131 | |
128 | curpos = *i; |
132 | curpos = *i; |
129 | } |
133 | } |
130 | |
134 | |
|
|
135 | // declare these here to get correct initialisation order |
|
|
136 | #define def(str) const shstr shstr_ ## str (# str); |
|
|
137 | # include "shstrinc.h" |
|
|
138 | #undef def |
|
|
139 | |
131 | shstr skill_names[NUM_SKILLS]; |
140 | shstr skill_names[NUM_SKILLS]; |
132 | |
|
|
133 | // what weird misoptimisation is this again? |
|
|
134 | const shstr undead_name ("undead"); |
|
|
135 | |
141 | |
136 | //TODO: this should of course not be here |
142 | //TODO: this should of course not be here |
137 | |
143 | |
138 | /* buf_overflow() - we don't want to exceed the buffer size of |
144 | /* buf_overflow() - we don't want to exceed the buffer size of |
139 | * buf1 by adding on buf2! Returns true if overflow will occur. |
145 | * buf1 by adding on buf2! Returns true if overflow will occur. |
… | |
… | |
143 | { |
149 | { |
144 | int len1 = 0, len2 = 0; |
150 | int len1 = 0, len2 = 0; |
145 | |
151 | |
146 | if (buf1) |
152 | if (buf1) |
147 | len1 = strlen (buf1); |
153 | len1 = strlen (buf1); |
|
|
154 | |
148 | if (buf2) |
155 | if (buf2) |
149 | len2 = strlen (buf2); |
156 | len2 = strlen (buf2); |
|
|
157 | |
150 | if ((len1 + len2) >= bufsize) |
158 | if ((len1 + len2) >= bufsize) |
151 | return 1; |
159 | return 1; |
152 | |
160 | |
153 | return 0; |
161 | return 0; |
154 | } |
162 | } |