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-github-7e2015a46df7976bddee313b994742e49e420714.tar.gz |
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 @@ /* -** $Id: lobject.h,v 2.105 2014/12/19 13:36:32 roberto Exp roberto $ +** $Id: lobject.h,v 2.106 2015/01/05 13:52:37 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -303,9 +303,12 @@ typedef TValue *StkId; /* index to stack elements */ typedef struct TString { CommonHeader; lu_byte extra; /* reserved words for short strings; "has hash" for longs */ + lu_byte shrlen; /* length for short strings */ unsigned int hash; - size_t len; /* number of characters in string */ - struct TString *hnext; /* linked list for hash table */ + union { + size_t lnglen; /* length for long strings */ + struct TString *hnext; /* linked list for hash table */ + } u; } TString; @@ -329,6 +332,12 @@ typedef union UTString { /* get the actual string (array of bytes) from a Lua value */ #define svalue(o) getstr(tsvalue(o)) +/* get string length from 'TString *s' */ +#define tsslen(s) ((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen) + +/* get string length from 'TValue *o' */ +#define vslen(o) tsslen(tsvalue(o)) + /* ** Header for userdata; memory area follows the end of this structure |