summaryrefslogtreecommitdiff
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-github-41964648eea1427d53934b886abb68cc8457b019.tar.gz
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 @@
/*
-** $Id: lundump.c,v 2.40 2014/06/19 18:27:20 roberto Exp roberto $
+** $Id: lundump.c,v 2.41 2014/11/02 19:19:04 roberto Exp roberto $
** load precompiled Lua chunks
** See Copyright Notice in lua.h
*/
@@ -32,7 +32,6 @@
typedef struct {
lua_State *L;
ZIO *Z;
- Mbuffer *b;
const char *name;
} LoadState;
@@ -92,10 +91,15 @@ static TString *LoadString (LoadState *S) {
LoadVar(S, size);
if (size == 0)
return NULL;
- else {
- char *s = luaZ_openspace(S->L, S->b, --size);
- LoadVector(S, s, size);
- return luaS_newlstr(S->L, s, size);
+ else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */
+ char buff[LUAI_MAXSHORTLEN];
+ LoadVector(S, buff, size);
+ return luaS_newlstr(S->L, buff, size);
+ }
+ else { /* long string */
+ TString *ts = luaS_createlngstrobj(S->L, size);
+ LoadVector(S, getaddrstr(ts), size); /* load directly in final place */
+ return ts;
}
}
@@ -251,8 +255,7 @@ static void checkHeader (LoadState *S) {
/*
** load precompiled chunk
*/
-LClosure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff,
- const char *name) {
+LClosure *luaU_undump(lua_State *L, ZIO *Z, const char *name) {
LoadState S;
LClosure *cl;
if (*name == '@' || *name == '=')
@@ -263,7 +266,6 @@ LClosure *luaU_undump(lua_State *L, ZIO *Z, Mbuffer *buff,
S.name = name;
S.L = L;
S.Z = Z;
- S.b = buff;
checkHeader(&S);
cl = luaF_newLclosure(L, LoadByte(&S));
setclLvalue(L, L->top, cl);