… | |
… | |
10 | |
10 | |
11 | #include <tr1/unordered_set> |
11 | #include <tr1/unordered_set> |
12 | |
12 | |
13 | #include "global.h" |
13 | #include "global.h" |
14 | |
14 | |
15 | typedef std::tr1::unordered_set<const char *, str_hash, str_equal> HT; |
15 | typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *>, true> HT; |
16 | |
16 | |
17 | static HT ht; |
17 | static HT ht; |
18 | |
18 | |
19 | static const char * |
19 | static const char * |
20 | makevec (const char *s) |
20 | makevec (const char *s) |
21 | { |
21 | { |
22 | int |
|
|
23 | len = strlen (s); |
22 | int len = strlen (s); |
24 | |
23 | |
25 | const char * |
|
|
26 | v = (const char *) (2 + (int *) g_slice_alloc (sizeof (int) * 2 + len + 1)); |
24 | const char *v = (const char *) (2 + (int *)g_slice_alloc (sizeof (int) * 2 + len + 1)); |
27 | |
25 | |
28 | shstr::length (v) = len; |
26 | shstr::length (v) = len; |
29 | shstr::refcnt (v) = 1; |
27 | shstr::refcnt (v) = 1; |
30 | |
28 | |
31 | memcpy ((char *) v, s, len + 1); |
29 | memcpy ((char *) v, s, len + 1); |
32 | |
30 | |
33 | return v; |
31 | return v; |
34 | } |
32 | } |
35 | |
33 | |
|
|
34 | static const char * |
|
|
35 | makenull () |
|
|
36 | { |
|
|
37 | const char *s = makevec ("(null)"); |
|
|
38 | shstr::length (s) = 0; |
|
|
39 | return s; |
|
|
40 | } |
|
|
41 | |
36 | const char *shstr::null = makevec ("<nil>"); |
42 | const char *shstr::null = makenull (); |
37 | |
43 | |
38 | const char * |
44 | const char * |
39 | shstr::find (const char *s) |
45 | shstr::find (const char *s) |
40 | { |
46 | { |
41 | if (!s) |
47 | if (!s) |