aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-03-01 12:18:44 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-03-01 12:18:44 -0300
commitf69e0ade19af4d997f52c03881362a6961383487 (patch)
tree4ee16763cb070c92e2d985bc3a57b73e99698b53
parent99a1c06ea34c823e7692deac3a23fec4831d8f79 (diff)
downloadlua-f69e0ade19af4d997f52c03881362a6961383487.tar.gz
lua-f69e0ade19af4d997f52c03881362a6961383487.tar.bz2
lua-f69e0ade19af4d997f52c03881362a6961383487.zip
no need to store a full 'size_t' fo the size of (frequent) small strings
-rw-r--r--ldump.c22
-rw-r--r--lundump.c10
2 files changed, 16 insertions, 16 deletions
diff --git a/ldump.c b/ldump.c
index 1078910f..5f0b7a46 100644
--- a/ldump.c
+++ b/ldump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldump.c,v 2.22 2014/02/28 12:25:12 roberto Exp roberto $ 2** $Id: ldump.c,v 2.23 2014/02/28 16:13:01 roberto Exp roberto $
3** save precompiled Lua chunks 3** save precompiled Lua chunks
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -60,16 +60,16 @@ static void DumpInteger(lua_Integer x, DumpState* D)
60 60
61static void DumpString(const TString* s, DumpState* D) 61static void DumpString(const TString* s, DumpState* D)
62{ 62{
63 if (s==NULL) 63 if (s==NULL) DumpByte(0,D);
64 { 64 else {
65 size_t size=0; 65 size_t size = s->tsv.len+1; /* include trailing '\0' */
66 DumpVar(size,D); 66 if (size < 0xFF) DumpByte(size,D);
67 } 67 else
68 else 68 {
69 { 69 DumpByte(0xFF,D);
70 size_t size=s->tsv.len+1; /* include trailing '\0' */ 70 DumpVar(size,D);
71 DumpVar(size,D); 71 }
72 DumpBlock(getstr(s),size*sizeof(char),D); 72 DumpVector(getstr(s),size-1,D); /* no need to save '\0' */
73 } 73 }
74} 74}
75 75
diff --git a/lundump.c b/lundump.c
index ef7444e0..9a3ee218 100644
--- a/lundump.c
+++ b/lundump.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lundump.c,v 2.28 2014/02/28 12:25:12 roberto Exp roberto $ 2** $Id: lundump.c,v 2.29 2014/02/28 16:13:01 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*/
@@ -76,15 +76,15 @@ static lua_Integer LoadInteger(LoadState* S)
76 76
77static TString* LoadString(LoadState* S) 77static TString* LoadString(LoadState* S)
78{ 78{
79 size_t size; 79 size_t size = LoadByte(S);
80 LoadVar(S,size); 80 if (size == 0xFF) LoadVar(S,size);
81 if (size==0) 81 if (size==0)
82 return NULL; 82 return NULL;
83 else 83 else
84 { 84 {
85 char* s=luaZ_openspace(S->L,S->b,size); 85 char* s=luaZ_openspace(S->L,S->b,--size);
86 LoadVector(S,s,size); 86 LoadVector(S,s,size);
87 return luaS_newlstr(S->L,s,size-1); /* remove trailing '\0' */ 87 return luaS_newlstr(S->L,s,size);
88 } 88 }
89} 89}
90 90