aboutsummaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/lstring.c b/lstring.c
index 13dcaf42..1032ad86 100644
--- a/lstring.c
+++ b/lstring.c
@@ -36,7 +36,7 @@ int luaS_eqlngstr (TString *a, TString *b) {
36 lua_assert(a->tt == LUA_VLNGSTR && b->tt == LUA_VLNGSTR); 36 lua_assert(a->tt == LUA_VLNGSTR && b->tt == LUA_VLNGSTR);
37 return (a == b) || /* same instance or... */ 37 return (a == b) || /* same instance or... */
38 ((len == b->u.lnglen) && /* equal length and ... */ 38 ((len == b->u.lnglen) && /* equal length and ... */
39 (memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */ 39 (memcmp(getlngstr(a), getlngstr(b), len) == 0)); /* equal contents */
40} 40}
41 41
42 42
@@ -52,7 +52,7 @@ unsigned int luaS_hashlongstr (TString *ts) {
52 lua_assert(ts->tt == LUA_VLNGSTR); 52 lua_assert(ts->tt == LUA_VLNGSTR);
53 if (ts->extra == 0) { /* no hash? */ 53 if (ts->extra == 0) { /* no hash? */
54 size_t len = ts->u.lnglen; 54 size_t len = ts->u.lnglen;
55 ts->hash = luaS_hash(getstr(ts), len, ts->hash); 55 ts->hash = luaS_hash(getlngstr(ts), len, ts->hash);
56 ts->extra = 1; /* now it has its hash */ 56 ts->extra = 1; /* now it has its hash */
57 } 57 }
58 return ts->hash; 58 return ts->hash;
@@ -157,6 +157,7 @@ static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) {
157TString *luaS_createlngstrobj (lua_State *L, size_t l) { 157TString *luaS_createlngstrobj (lua_State *L, size_t l) {
158 TString *ts = createstrobj(L, l, LUA_VLNGSTR, G(L)->seed); 158 TString *ts = createstrobj(L, l, LUA_VLNGSTR, G(L)->seed);
159 ts->u.lnglen = l; 159 ts->u.lnglen = l;
160 ts->shrlen = 0xFF; /* signals that it is a long string */
160 return ts; 161 return ts;
161} 162}
162 163
@@ -193,7 +194,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) {
193 TString **list = &tb->hash[lmod(h, tb->size)]; 194 TString **list = &tb->hash[lmod(h, tb->size)];
194 lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */ 195 lua_assert(str != NULL); /* otherwise 'memcmp'/'memcpy' are undefined */
195 for (ts = *list; ts != NULL; ts = ts->u.hnext) { 196 for (ts = *list; ts != NULL; ts = ts->u.hnext) {
196 if (l == ts->shrlen && (memcmp(str, getstr(ts), l * sizeof(char)) == 0)) { 197 if (l == ts->shrlen && (memcmp(str, getshrstr(ts), l * sizeof(char)) == 0)) {
197 /* found! */ 198 /* found! */
198 if (isdead(g, ts)) /* dead (but not collected yet)? */ 199 if (isdead(g, ts)) /* dead (but not collected yet)? */
199 changewhite(ts); /* resurrect it */ 200 changewhite(ts); /* resurrect it */
@@ -206,7 +207,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) {
206 list = &tb->hash[lmod(h, tb->size)]; /* rehash with new size */ 207 list = &tb->hash[lmod(h, tb->size)]; /* rehash with new size */
207 } 208 }
208 ts = createstrobj(L, l, LUA_VSHRSTR, h); 209 ts = createstrobj(L, l, LUA_VSHRSTR, h);
209 memcpy(getstr(ts), str, l * sizeof(char)); 210 memcpy(getshrstr(ts), str, l * sizeof(char));
210 ts->shrlen = cast_byte(l); 211 ts->shrlen = cast_byte(l);
211 ts->u.hnext = *list; 212 ts->u.hnext = *list;
212 *list = ts; 213 *list = ts;
@@ -226,7 +227,7 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
226 if (l_unlikely(l >= (MAX_SIZE - sizeof(TString))/sizeof(char))) 227 if (l_unlikely(l >= (MAX_SIZE - sizeof(TString))/sizeof(char)))
227 luaM_toobig(L); 228 luaM_toobig(L);
228 ts = luaS_createlngstrobj(L, l); 229 ts = luaS_createlngstrobj(L, l);
229 memcpy(getstr(ts), str, l * sizeof(char)); 230 memcpy(getlngstr(ts), str, l * sizeof(char));
230 return ts; 231 return ts;
231 } 232 }
232} 233}