… | |
… | |
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 | } |
… | |
… | |
145 | { |
149 | { |
146 | int len1 = 0, len2 = 0; |
150 | int len1 = 0, len2 = 0; |
147 | |
151 | |
148 | if (buf1) |
152 | if (buf1) |
149 | len1 = strlen (buf1); |
153 | len1 = strlen (buf1); |
|
|
154 | |
150 | if (buf2) |
155 | if (buf2) |
151 | len2 = strlen (buf2); |
156 | len2 = strlen (buf2); |
|
|
157 | |
152 | if ((len1 + len2) >= bufsize) |
158 | if ((len1 + len2) >= bufsize) |
153 | return 1; |
159 | return 1; |
154 | |
160 | |
155 | return 0; |
161 | return 0; |
156 | } |
162 | } |