(svn r26841) -Codechange [Squirrel]: move the actual initialisation of instance variables of SQString into the constructor

This commit is contained in:
rubidium 2014-09-16 21:13:24 +00:00
parent 1685118169
commit a1d4148be5
2 changed files with 11 additions and 6 deletions

View File

@ -523,11 +523,7 @@ SQString *SQStringTable::Add(const SQChar *news,SQInteger len)
}
SQString *t=(SQString *)SQ_MALLOC(len+sizeof(SQString));
new (t) SQString;
memcpy(t->_val,news,(size_t)len);
t->_val[len] = '\0';
t->_len = len;
t->_hash = ::_hashstr(news,(size_t)len);
new (t) SQString(news, len);
t->_next = _strings[h];
_strings[h] = t;
_slotused++;
@ -536,6 +532,15 @@ SQString *SQStringTable::Add(const SQChar *news,SQInteger len)
return t;
}
SQString::SQString(const SQChar *news, SQInteger len)
{
memcpy(_val,news,(size_t)len);
_val[len] = '\0';
_len = len;
_hash = ::_hashstr(news,(size_t)len);
_next = NULL;
}
void SQStringTable::Resize(SQInteger size)
{
SQInteger oldsize=_numofslots;

View File

@ -13,7 +13,7 @@ inline SQHash _hashstr (const SQChar *s, size_t l)
struct SQString : public SQRefCounted
{
SQString(){}
SQString(const SQChar *news, SQInteger len);
~SQString(){}
public:
static SQString *Create(SQSharedState *ss, const SQChar *, SQInteger len = -1 );