diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-01-16 14:54:37 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-01-16 14:54:37 -0200 |
| commit | 7e2015a46df7976bddee313b994742e49e420714 (patch) | |
| tree | 0b2db30f1214a478ccb3664d165c8a431f0d5850 /lobject.h | |
| parent | 5b01cb39b5ec36c544152351c35c43149d9bbfec (diff) | |
| download | lua-7e2015a46df7976bddee313b994742e49e420714.tar.gz lua-7e2015a46df7976bddee313b994742e49e420714.tar.bz2 lua-7e2015a46df7976bddee313b994742e49e420714.zip | |
size of short strings stored in a single byte, to reduce the size
of struct 'TString'
Diffstat (limited to 'lobject.h')
| -rw-r--r-- | lobject.h | 15 |
1 files changed, 12 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.h,v 2.105 2014/12/19 13:36:32 roberto Exp roberto $ | 2 | ** $Id: lobject.h,v 2.106 2015/01/05 13:52:37 roberto Exp roberto $ |
| 3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -303,9 +303,12 @@ typedef TValue *StkId; /* index to stack elements */ | |||
| 303 | typedef struct TString { | 303 | typedef struct TString { |
| 304 | CommonHeader; | 304 | CommonHeader; |
| 305 | lu_byte extra; /* reserved words for short strings; "has hash" for longs */ | 305 | lu_byte extra; /* reserved words for short strings; "has hash" for longs */ |
| 306 | lu_byte shrlen; /* length for short strings */ | ||
| 306 | unsigned int hash; | 307 | unsigned int hash; |
| 307 | size_t len; /* number of characters in string */ | 308 | union { |
| 308 | struct TString *hnext; /* linked list for hash table */ | 309 | size_t lnglen; /* length for long strings */ |
| 310 | struct TString *hnext; /* linked list for hash table */ | ||
| 311 | } u; | ||
| 309 | } TString; | 312 | } TString; |
| 310 | 313 | ||
| 311 | 314 | ||
| @@ -329,6 +332,12 @@ typedef union UTString { | |||
| 329 | /* get the actual string (array of bytes) from a Lua value */ | 332 | /* get the actual string (array of bytes) from a Lua value */ |
| 330 | #define svalue(o) getstr(tsvalue(o)) | 333 | #define svalue(o) getstr(tsvalue(o)) |
| 331 | 334 | ||
| 335 | /* get string length from 'TString *s' */ | ||
| 336 | #define tsslen(s) ((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen) | ||
| 337 | |||
| 338 | /* get string length from 'TValue *o' */ | ||
| 339 | #define vslen(o) tsslen(tsvalue(o)) | ||
| 340 | |||
| 332 | 341 | ||
| 333 | /* | 342 | /* |
| 334 | ** Header for userdata; memory area follows the end of this structure | 343 | ** Header for userdata; memory area follows the end of this structure |
