aboutsummaryrefslogtreecommitdiff
path: root/lundump.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-09-08 12:41:05 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-09-08 12:41:05 -0300
commit41964648eea1427d53934b886abb68cc8457b019 (patch)
treeb0388dfebe6614d5d49306193faf78f8b9e1a6a1 /lundump.c
parent502214f8a551cd01d94677f98a40aa51531ef71d (diff)
downloadlua-41964648eea1427d53934b886abb68cc8457b019.tar.gz
lua-41964648eea1427d53934b886abb68cc8457b019.tar.bz2
lua-41964648eea1427d53934b886abb68cc8457b019.zip
long strings are created directly in final position when possible
(instead of using an auxiliar buffer to first create the string and then allocate the final string and copy result there)
Diffstat (limited to 'lundump.c')
-rw-r--r--lundump.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/lundump.c b/lundump.c
index 039e4a0f..50c9f0fe 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 2.40 2014/06/19 18:27:20 roberto Exp roberto $ 2** $Id: lundump.c,v 2.41 2014/11/02 19:19:04 roberto Exp roberto $
3** load precompiled Lua chunks 3** load precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -32,7 +32,6 @@
32typedef struct { 32typedef struct {
33 lua_State *L; 33 lua_State *L;
34 ZIO *Z; 34 ZIO *Z;
35 Mbuffer *b;
36 const char *name; 35 const char *name;
37} LoadState; 36} LoadState;
38 37
@@ -92,10 +91,15 @@ static TString *LoadString (LoadState *S) {
92 LoadVar(S, size); 91 LoadVar(S, size);
93 if (size == 0) 92 if (size == 0)
94 return NULL; 93 return NULL;
95 else { 94 else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */
96 char *s = luaZ_openspace(S->L, S->b, --size); 95 char buff[LUAI_MAXSHORTLEN];
97 LoadVector(S, s, size); 96 LoadVector(S, buff, size);
98 return luaS_newlstr(S->L, s, size); 97 return luaS_newlstr(S->L, buff, size);
98 }
99 else { /* long string */
100 TString *ts = luaS_createlngstrobj(S->L, size);
101 LoadVector(S, getaddrstr(ts), size); /* load directly in final place */
102 return ts;
99 } 103 }
100} 104}
101 105
@@ -251,8 +255,7 @@ static void checkHeader (LoadState *S) {
251/* 255/*
252** load precompiled chunk 256** load precompiled chunk
253*/ 257*/
254LClosure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff, 258LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
255 const char *name) {
256 LoadState S; 259 LoadState S;
257 LClosure *cl; 260 LClosure *cl;
258 if (*name == '@' || *name == '=') 261 if (*name == '@' || *name == '=')
@@ -263,7 +266,6 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff,
263 S.name = name; 266 S.name = name;
264 S.L = L; 267 S.L = L;
265 S.Z = Z; 268 S.Z = Z;
266 S.b = buff;
267 checkHeader(&S); 269 checkHeader(&S);
268 cl = luaF_newLclosure(L, LoadByte(&S)); 270 cl = luaF_newLclosure(L, LoadByte(&S));
269 setclLvalue(L, L->top, cl); 271 setclLvalue(L, L->top, cl);