1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * |
5 | * |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
6 | * Deliantra is free software: you can redistribute it and/or modify it under |
7 | * the terms of the Affero GNU General Public License as published by the |
7 | * the terms of the Affero GNU General Public License as published by the |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
8 | * Free Software Foundation, either version 3 of the License, or (at your |
9 | * option) any later version. |
9 | * option) any later version. |
… | |
… | |
36 | typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *> > HT; |
36 | typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *> > HT; |
37 | |
37 | |
38 | static HT ht; |
38 | static HT ht; |
39 | static int next_gc; |
39 | static int next_gc; |
40 | |
40 | |
|
|
41 | #define NUM_INT 3 |
|
|
42 | |
41 | static const char * |
43 | static const char * |
42 | makevec (const char *s) |
44 | makevec (const char *s) |
43 | { |
45 | { |
44 | int len = strlen (s); |
46 | int len = strlen (s); |
45 | int alloc = sizeof (uint32_t) * 2 + len + 1; |
47 | int alloc = sizeof (uint32_t) * NUM_INT + len + 1; |
46 | |
48 | |
47 | shstr_alloc += alloc; |
49 | shstr_alloc += alloc; |
48 | char *v = (char *)g_slice_alloc (alloc); |
50 | char *v = (char *)g_slice_alloc (alloc); |
49 | v += sizeof (uint32_t) * 2; |
51 | v += sizeof (uint32_t) * NUM_INT; |
50 | |
52 | |
|
|
53 | shstr::hash (v) = strhsh (s); |
51 | shstr::length (v) = len; |
54 | shstr::length (v) = len; |
52 | shstr::refcnt (v) = 1; |
55 | shstr::refcnt (v) = 1; |
53 | |
56 | |
54 | memcpy (v, s, len + 1); |
57 | memcpy (v, s, len + 1); |
55 | |
58 | |
56 | return v; |
59 | return v; |
57 | } |
60 | } |
58 | |
61 | |
59 | shstr_vec<sizeof "(null)"> shstr_tmp::nullvec = { 0, 0xffffffff, "(null)" }; |
62 | shstr_vec<sizeof "(null)"> shstr_tmp::nullvec = { STRHSH_NULL, 0, 0xffffffff, "(null)" }; |
60 | |
63 | |
61 | const char * |
64 | const char * |
62 | shstr::find (const char *s) |
65 | shstr::find (const char *s) |
63 | { |
66 | { |
64 | if (!s) |
67 | if (!s) |
… | |
… | |
120 | const char *s = *o; |
123 | const char *s = *o; |
121 | |
124 | |
122 | ht.erase (o); |
125 | ht.erase (o); |
123 | |
126 | |
124 | //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); |
127 | //printf ("GC %4d %3d %d >%s<%d\n", (int)ht.size (), n, shstr::refcnt (s), s, shstr::length (s)); |
125 | int alloc = sizeof (uint32_t) * 2 + length (s) + 1; |
128 | int alloc = sizeof (uint32_t) * NUM_INT + length (s) + 1; |
126 | shstr_alloc -= alloc; |
129 | shstr_alloc -= alloc; |
127 | g_slice_free1 (alloc, (void *)(s - sizeof (uint32_t) * 2)); |
130 | g_slice_free1 (alloc, (void *)(s - sizeof (uint32_t) * NUM_INT)); |
128 | } |
131 | } |
129 | else |
132 | else |
130 | ++i; |
133 | ++i; |
131 | } |
134 | } |
132 | |
135 | |
… | |
… | |
138 | #define def(id) def2(shstr_ ## id, # id) |
141 | #define def(id) def2(shstr_ ## id, # id) |
139 | # include "shstrinc.h" |
142 | # include "shstrinc.h" |
140 | #undef def |
143 | #undef def |
141 | #undef def2 |
144 | #undef def2 |
142 | |
145 | |
143 | shstr skill_names[NUM_SKILLS]; |
146 | materialtype_t material_null; |
144 | |
147 | |