sqstring.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* see copyright notice in squirrel.h */
  2. #ifndef _SQSTRING_H_
  3. #define _SQSTRING_H_
  4. inline SQHash _hashstr (const SQChar *s, size_t l)
  5. {
  6. SQHash h = (SQHash)l; /* seed */
  7. size_t step = (l>>5)+1; /* if string is too long, don't hash all its chars */
  8. for (; l>=step; l-=step)
  9. h ^= ((h<<5)+(h>>2)+(SQUChar)(s[l-1]));
  10. return h;
  11. }
  12. #define SQSTRING_PAD_VAL (sizeof(void*))
  13. #define SQSTRING_CALCULATED_SIZE(sl) \
  14. ((sl >= SQSTRING_PAD_VAL) ? (sizeof(SQString)+(sl-SQSTRING_PAD_VAL+1)) \
  15. : (sizeof(SQString)))
  16. struct SQString : public SQRefCounted
  17. {
  18. SQString(){}
  19. ~SQString(){}
  20. public:
  21. static SQString *Create(SQSharedState *ss, const SQChar *, SQInteger len = -1 );
  22. static SQString *Create(SQSharedState *ss, SQString * );
  23. SQInteger Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
  24. void Release();
  25. SQSharedState *_sharedstate;
  26. SQString *_next; //chain for the string table
  27. SQInteger _len;
  28. SQHash _hash;
  29. SQChar _val[SQSTRING_PAD_VAL];
  30. //<FIXME> Padding not accounted
  31. };
  32. struct SQStringUtf8 : public SQString {
  33. SQInteger Next(const SQObjectPtr &refpos, SQObjectPtr &outkey, SQObjectPtr &outval);
  34. };
  35. #endif //_SQSTRING_H_