diff options
Diffstat (limited to 'lstring.c')
-rw-r--r-- | lstring.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstring.c,v 2.49 2015/06/01 16:34:37 roberto Exp roberto $ | 2 | ** $Id: lstring.c,v 2.50 2015/06/18 14:20:32 roberto Exp roberto $ |
3 | ** String table (keeps all strings handled by Lua) | 3 | ** String table (keeps all strings handled by Lua) |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -119,8 +119,7 @@ void luaS_init (lua_State *L) { | |||
119 | /* | 119 | /* |
120 | ** creates a new string object | 120 | ** creates a new string object |
121 | */ | 121 | */ |
122 | static TString *createstrobj (lua_State *L, const char *str, size_t l, | 122 | static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h) { |
123 | int tag, unsigned int h) { | ||
124 | TString *ts; | 123 | TString *ts; |
125 | GCObject *o; | 124 | GCObject *o; |
126 | size_t totalsize; /* total size of TString object */ | 125 | size_t totalsize; /* total size of TString object */ |
@@ -129,12 +128,18 @@ static TString *createstrobj (lua_State *L, const char *str, size_t l, | |||
129 | ts = gco2ts(o); | 128 | ts = gco2ts(o); |
130 | ts->hash = h; | 129 | ts->hash = h; |
131 | ts->extra = 0; | 130 | ts->extra = 0; |
132 | memcpy(getaddrstr(ts), str, l * sizeof(char)); | ||
133 | getaddrstr(ts)[l] = '\0'; /* ending 0 */ | 131 | getaddrstr(ts)[l] = '\0'; /* ending 0 */ |
134 | return ts; | 132 | return ts; |
135 | } | 133 | } |
136 | 134 | ||
137 | 135 | ||
136 | TString *luaS_createlngstrobj (lua_State *L, size_t l) { | ||
137 | TString *ts = createstrobj(L, l, LUA_TLNGSTR, G(L)->seed); | ||
138 | ts->u.lnglen = l; | ||
139 | return ts; | ||
140 | } | ||
141 | |||
142 | |||
138 | void luaS_remove (lua_State *L, TString *ts) { | 143 | void luaS_remove (lua_State *L, TString *ts) { |
139 | stringtable *tb = &G(L)->strt; | 144 | stringtable *tb = &G(L)->strt; |
140 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; | 145 | TString **p = &tb->hash[lmod(ts->hash, tb->size)]; |
@@ -166,7 +171,8 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { | |||
166 | luaS_resize(L, g->strt.size * 2); | 171 | luaS_resize(L, g->strt.size * 2); |
167 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ | 172 | list = &g->strt.hash[lmod(h, g->strt.size)]; /* recompute with new size */ |
168 | } | 173 | } |
169 | ts = createstrobj(L, str, l, LUA_TSHRSTR, h); | 174 | ts = createstrobj(L, l, LUA_TSHRSTR, h); |
175 | memcpy(getaddrstr(ts), str, l * sizeof(char)); | ||
170 | ts->shrlen = cast_byte(l); | 176 | ts->shrlen = cast_byte(l); |
171 | ts->u.hnext = *list; | 177 | ts->u.hnext = *list; |
172 | *list = ts; | 178 | *list = ts; |
@@ -185,8 +191,8 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) { | |||
185 | TString *ts; | 191 | TString *ts; |
186 | if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char)) | 192 | if (l >= (MAX_SIZE - sizeof(TString))/sizeof(char)) |
187 | luaM_toobig(L); | 193 | luaM_toobig(L); |
188 | ts = createstrobj(L, str, l, LUA_TLNGSTR, G(L)->seed); | 194 | ts = luaS_createlngstrobj(L, l); |
189 | ts->u.lnglen = l; | 195 | memcpy(getaddrstr(ts), str, l * sizeof(char)); |
190 | return ts; | 196 | return ts; |
191 | } | 197 | } |
192 | } | 198 | } |