… | |
… | |
8 | |
8 | |
9 | #include <glib.h> |
9 | #include <glib.h> |
10 | |
10 | |
11 | #include <tr1/unordered_set> |
11 | #include <tr1/unordered_set> |
12 | |
12 | |
13 | #include "shstr.h" |
|
|
14 | #include "util.h" |
13 | #include "global.h" |
15 | |
14 | |
16 | typedef |
15 | typedef std::tr1::unordered_set<const char *, str_hash, str_equal> HT; |
17 | std::tr1::unordered_set < const char *, |
|
|
18 | str_hash, |
|
|
19 | str_equal > |
|
|
20 | HT; |
|
|
21 | |
16 | |
22 | static HT |
17 | static HT ht; |
23 | ht; |
|
|
24 | |
18 | |
25 | static const char * |
19 | static const char * |
26 | makevec (const char *s) |
20 | makevec (const char *s) |
27 | { |
21 | { |
28 | int |
|
|
29 | len = strlen (s); |
22 | int len = strlen (s); |
30 | |
23 | |
31 | const char * |
|
|
32 | 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)); |
33 | |
25 | |
34 | shstr::length (v) = len; |
26 | shstr::length (v) = len; |
35 | shstr::refcnt (v) = 1; |
27 | shstr::refcnt (v) = 1; |
36 | |
28 | |
37 | memcpy ((char *) v, s, len + 1); |
29 | memcpy ((char *) v, s, len + 1); |
38 | |
30 | |
39 | return v; |
31 | return v; |
40 | } |
32 | } |
41 | |
33 | |
42 | const char * |
34 | static const char * |
43 | shstr::null = makevec ("<nil>"); |
35 | makenull () |
|
|
36 | { |
|
|
37 | const char *s = makevec ("(null)"); |
|
|
38 | shstr::length (s) = 0; |
|
|
39 | return s; |
|
|
40 | } |
44 | |
41 | |
45 | // what weird misoptimisation is this again? |
42 | const char *shstr::null = makenull (); |
46 | const shstr undead_name ("undead"); |
|
|
47 | |
43 | |
48 | const char * |
44 | const char * |
49 | shstr::find (const char *s) |
45 | shstr::find (const char *s) |
50 | { |
46 | { |
51 | if (!s) |
47 | if (!s) |
… | |
… | |
115 | } |
111 | } |
116 | |
112 | |
117 | curpos = *i; |
113 | curpos = *i; |
118 | } |
114 | } |
119 | |
115 | |
|
|
116 | shstr skill_names[NUM_SKILLS]; |
|
|
117 | |
|
|
118 | // what weird misoptimisation is this again? |
|
|
119 | const shstr undead_name ("undead"); |
|
|
120 | |
120 | //TODO: this should of course not be here |
121 | //TODO: this should of course not be here |
121 | |
122 | |
122 | /* buf_overflow() - we don't want to exceed the buffer size of |
123 | /* buf_overflow() - we don't want to exceed the buffer size of |
123 | * buf1 by adding on buf2! Returns true if overflow will occur. |
124 | * buf1 by adding on buf2! Returns true if overflow will occur. |
124 | */ |
125 | */ |