… | |
… | |
33 | extern int buf_overflow (const char *buf1, const char *buf2, int bufsize); |
33 | extern int buf_overflow (const char *buf1, const char *buf2, int bufsize); |
34 | |
34 | |
35 | template<int size> |
35 | template<int size> |
36 | struct shstr_vec |
36 | struct shstr_vec |
37 | { |
37 | { |
|
|
38 | uint32_t hash; |
38 | uint32_t len; |
39 | uint32_t len; |
39 | uint32_t refcnt; |
40 | uint32_t refcnt; |
|
|
41 | // pointer points here |
40 | char string[size]; |
42 | char string [size]; |
41 | }; |
43 | }; |
42 | |
44 | |
43 | // this class is a non-refcounted shared string |
45 | // this class is a non-refcounted shared string |
44 | // it cannot be used to create or store shared strings, but |
46 | // it cannot be used to create or store shared strings, but |
45 | // it can be used to apss shared strings around, i.e. as function arguments |
47 | // it can be used to apss shared strings around, i.e. as function arguments |
… | |
… | |
50 | static shstr_vec<sizeof ("(null)")> nullvec; |
52 | static shstr_vec<sizeof ("(null)")> nullvec; |
51 | static const char *null () { return nullvec.string; } // this is the null pointer value |
53 | static const char *null () { return nullvec.string; } // this is the null pointer value |
52 | |
54 | |
53 | const char *s; |
55 | const char *s; |
54 | |
56 | |
|
|
57 | static unsigned int &hash (const char *s) |
|
|
58 | { |
|
|
59 | return *((unsigned int *)s - 3); |
|
|
60 | } |
|
|
61 | |
|
|
62 | int hash () const |
|
|
63 | { |
|
|
64 | return hash (s); |
|
|
65 | } |
|
|
66 | |
55 | static unsigned int &length (const char *s) |
67 | static unsigned int &length (const char *s) |
56 | { |
68 | { |
57 | return *((unsigned int *)s - 2); |
69 | return *((unsigned int *)s - 2); |
58 | } |
70 | } |
59 | |
71 | |