summaryrefslogtreecommitdiff
path: root/src/lstring.c
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2014-07-31 12:00:00 +0000
committerrepogen <>2014-07-31 12:00:00 +0000
commitd7648e85b78d53a2248de909868192598ad0eb69 (patch)
treec67708a14fd29f8ff7e4981aadb041c5ab577e08 /src/lstring.c
parent3907bda05b0e73eba86487ad703e832ca14b64ce (diff)
downloadlua-github-5.3.0-alpha.tar.gz
Lua 5.3.0-alpha5.3.0-alpha
Diffstat (limited to 'src/lstring.c')
-rw-r--r--src/lstring.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/lstring.c b/src/lstring.c
index c63111a8..df28a7f2 100644
--- a/src/lstring.c
+++ b/src/lstring.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstring.c,v 2.40 2014/06/18 22:59:29 roberto Exp $
+** $Id: lstring.c,v 2.44 2014/07/21 16:02:10 roberto Exp $
** String table (keeps all strings handled by Lua)
** See Copyright Notice in lua.h
*/
@@ -34,10 +34,10 @@
** equality for long strings
*/
int luaS_eqlngstr (TString *a, TString *b) {
- size_t len = a->tsv.len;
- lua_assert(a->tsv.tt == LUA_TLNGSTR && b->tsv.tt == LUA_TLNGSTR);
+ size_t len = a->len;
+ lua_assert(a->tt == LUA_TLNGSTR && b->tt == LUA_TLNGSTR);
return (a == b) || /* same instance or... */
- ((len == b->tsv.len) && /* equal length and ... */
+ ((len == b->len) && /* equal length and ... */
(memcmp(getstr(a), getstr(b), len) == 0)); /* equal contents */
}
@@ -67,9 +67,9 @@ void luaS_resize (lua_State *L, int newsize) {
TString *p = tb->hash[i];
tb->hash[i] = NULL;
while (p) { /* for each node in the list */
- TString *hnext = p->tsv.hnext; /* save next */
- unsigned int h = lmod(p->tsv.hash, newsize); /* new position */
- p->tsv.hnext = tb->hash[h]; /* chain it */
+ TString *hnext = p->hnext; /* save next */
+ unsigned int h = lmod(p->hash, newsize); /* new position */
+ p->hnext = tb->hash[h]; /* chain it */
tb->hash[h] = p;
p = hnext;
}
@@ -92,24 +92,24 @@ static TString *createstrobj (lua_State *L, const char *str, size_t l,
TString *ts;
GCObject *o;
size_t totalsize; /* total size of TString object */
- totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
+ totalsize = sizelstring(l);
o = luaC_newobj(L, tag, totalsize);
- ts = rawgco2ts(o);
- ts->tsv.len = l;
- ts->tsv.hash = h;
- ts->tsv.extra = 0;
- memcpy(ts+1, str, l*sizeof(char));
- ((char *)(ts+1))[l] = '\0'; /* ending 0 */
+ ts = gco2ts(o);
+ ts->len = l;
+ ts->hash = h;
+ ts->extra = 0;
+ memcpy(getaddrstr(ts), str, l * sizeof(char));
+ getaddrstr(ts)[l] = '\0'; /* ending 0 */
return ts;
}
void luaS_remove (lua_State *L, TString *ts) {
stringtable *tb = &G(L)->strt;
- TString **p = &tb->hash[lmod(ts->tsv.hash, tb->size)];
+ TString **p = &tb->hash[lmod(ts->hash, tb->size)];
while (*p != ts) /* find previous element */
- p = &(*p)->tsv.hnext;
- *p = (*p)->tsv.hnext; /* remove element from its list */
+ p = &(*p)->hnext;
+ *p = (*p)->hnext; /* remove element from its list */
tb->nuse--;
}
@@ -122,12 +122,12 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) {
global_State *g = G(L);
unsigned int h = luaS_hash(str, l, g->seed);
TString **list = &g->strt.hash[lmod(h, g->strt.size)];
- for (ts = *list; ts != NULL; ts = ts->tsv.hnext) {
- if (l == ts->tsv.len &&
+ for (ts = *list; ts != NULL; ts = ts->hnext) {
+ if (l == ts->len &&
(memcmp(str, getstr(ts), l * sizeof(char)) == 0)) {
/* found! */
- if (isdead(g, obj2gco(ts))) /* dead (but not collected yet)? */
- changewhite(obj2gco(ts)); /* resurrect it */
+ if (isdead(g, ts)) /* dead (but not collected yet)? */
+ changewhite(ts); /* resurrect it */
return ts;
}
}
@@ -136,7 +136,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) {
list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */
}
ts = createstrobj(L, str, l, LUA_TSHRSTR, h);
- ts->tsv.hnext = *list;
+ ts->hnext = *list;
*list = ts;
g->strt.nuse++;
return ts;
@@ -170,10 +170,10 @@ Udata *luaS_newudata (lua_State *L, size_t s) {
GCObject *o;
if (s > MAX_SIZE - sizeof(Udata))
luaM_toobig(L);
- o = luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s);
- u = rawgco2u(o);
- u->uv.len = s;
- u->uv.metatable = NULL;
+ o = luaC_newobj(L, LUA_TUSERDATA, sizeludata(s));
+ u = gco2u(o);
+ u->len = s;
+ u->metatable = NULL;
setuservalue(L, u, luaO_nilobject);
return u;
}