--- deliantra/server/include/shstr.h 2008/12/31 17:35:37 1.24 +++ deliantra/server/include/shstr.h 2008/12/31 18:07:41 1.25 @@ -25,12 +25,20 @@ #include #include -#include "util.h" +#include "traits.h" extern size_t shstr_alloc; extern int buf_overflow (const char *buf1, const char *buf2, int bufsize); +template +struct shstr_vec +{ + uint32_t len; + uint32_t refcnt; + char string[size]; +}; + // this class is a non-refcounted shared string // it cannot be used to create or store shared strings, but // it can be used to apss shared strings around, i.e. as function arguments @@ -38,7 +46,8 @@ // they are only valid as temporary values within the same server tick. struct shstr_tmp { - static const char *null; + static shstr_vec nullvec; + static const char *null () { return nullvec.string; } // this is the null pointer value const char *s; @@ -67,7 +76,7 @@ } shstr_tmp () - : s (null) + : s (null ()) { } @@ -86,7 +95,7 @@ // this is used for informational messages and the like const char *operator &() const { return s; } - operator const char *() const { return s == null ? 0 : s; } + operator const char *() const { return s == null () ? 0 : s; } }; inline bool operator ==(const shstr_tmp &a, const shstr_tmp &b) @@ -149,7 +158,7 @@ explicit shstr (const char *str) { - s = is_constant (str) && !str ? null : intern (str); + s = is_constant (str) && !str ? null () : intern (str); } ~shstr () @@ -180,7 +189,7 @@ shstr &operator =(const char *str) { --refcnt (); - s = is_constant (str) && !str ? null : intern (str); + s = is_constant (str) && !str ? null () : intern (str); return *this; } @@ -197,12 +206,7 @@ { } - shstr_cmp (const shstr_cmp &sh) - : s (sh.s) - { - } - - shstr_cmp (const shstr &sh) + shstr_cmp (shstr_tmp sh) : s (sh.s) { } @@ -210,7 +214,6 @@ // this is used for informational messages and the like const char *operator &() const { return s; } - shstr_cmp operator =(const shstr_cmp sh) { s = sh.s; return *this; } operator const char *() const { return s; } }; @@ -224,8 +227,6 @@ return a.s == b.s; } -extern const shstr shstr_null; - #define def(str) extern const shstr shstr_ ## str; # include "shstrinc.h" #undef def