ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/shstr.C
(Generate patch)

Comparing deliantra/server/common/shstr.C (file contents):
Revision 1.14 by root, Mon Sep 11 23:33:28 2006 UTC vs.
Revision 1.19 by root, Wed Sep 13 23:39:27 2006 UTC

1
2/* 1/*
3 * shstr.C 2 * shstr.C
4 */ 3 */
5 4
6#include <cstring> 5#include <cstring>
8 7
9#include <glib.h> 8#include <glib.h>
10 9
11#include <tr1/unordered_set> 10#include <tr1/unordered_set>
12 11
13#include "shstr.h"
14#include "util.h" 12#include "global.h"
15 13
16typedef 14typedef std::tr1::unordered_set <const char *, str_hash, str_equal, slice_allocator<const char *>, true> HT;
17std::tr1::unordered_set < const char *,
18 str_hash,
19 str_equal >
20 HT;
21 15
22static HT 16static HT ht;
23 ht;
24 17
25static const char * 18static const char *
26makevec (const char *s) 19makevec (const char *s)
27{ 20{
28 int
29 len = strlen (s); 21 int len = strlen (s);
30 22
31 const char *
32 v = (const char *) (2 + (int *) g_slice_alloc (sizeof (int) * 2 + len + 1)); 23 const char *v = (const char *) (2 + (int *)g_slice_alloc (sizeof (int) * 2 + len + 1));
33 24
34 shstr::length (v) = len; 25 shstr::length (v) = len;
35 shstr::refcnt (v) = 1; 26 shstr::refcnt (v) = 1;
36 27
37 memcpy ((char *) v, s, len + 1); 28 memcpy ((char *) v, s, len + 1);
38 29
39 return v; 30 return v;
40} 31}
41 32
42const char * 33static const char *
43 shstr::null = makevec ("<nil>"); 34makenull ()
35{
36 const char *s = makevec ("(null)");
37 shstr::length (s) = 0;
38 return s;
39}
44 40
45// what weird misoptimisation is this again? 41const char *shstr::null = makenull ();
46const shstr undead_name ("undead");
47 42
48const char * 43const char *
49shstr::find (const char *s) 44shstr::find (const char *s)
50{ 45{
51 if (!s) 46 if (!s)
76// periodically test refcounts == 0 for a few strings 71// periodically test refcounts == 0 for a few strings
77// this is the ONLY thing that erases stuff from ht. keep it that way. 72// this is the ONLY thing that erases stuff from ht. keep it that way.
78void 73void
79shstr::gc () 74shstr::gc ()
80{ 75{
81return; //D
82//D currently disabled: some datastructures might still store them
83//D but their pointers will become invalidated
84 static const char *curpos; 76 static const char *curpos;
85 77
86 HT::iterator i = curpos ? ht.find (curpos) : ht.begin (); 78 HT::iterator i = curpos ? ht.find (curpos) : ht.begin ();
87 79
88 if (i == ht.end ()) 80 if (i == ht.end ())
115 } 107 }
116 108
117 curpos = *i; 109 curpos = *i;
118} 110}
119 111
112shstr skill_names[NUM_SKILLS];
113
114// what weird misoptimisation is this again?
115const shstr undead_name ("undead");
116
120//TODO: this should of course not be here 117//TODO: this should of course not be here
121 118
122/* buf_overflow() - we don't want to exceed the buffer size of 119/* buf_overflow() - we don't want to exceed the buffer size of
123 * buf1 by adding on buf2! Returns true if overflow will occur. 120 * buf1 by adding on buf2! Returns true if overflow will occur.
124 */ 121 */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines