소스 검색

no need to store a full 'size_t' fo the size of (frequent) small strings

Roberto Ierusalimschy 11 년 전
부모
커밋
f69e0ade19
2개의 변경된 파일16개의 추가작업 그리고 16개의 파일을 삭제
  1. 11 11
      ldump.c
  2. 5 5
      lundump.c

+ 11 - 11
ldump.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: ldump.c,v 2.22 2014/02/28 12:25:12 roberto Exp roberto $
+** $Id: ldump.c,v 2.23 2014/02/28 16:13:01 roberto Exp roberto $
 ** save precompiled Lua chunks
 ** save precompiled Lua chunks
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -60,16 +60,16 @@ static void DumpInteger(lua_Integer x, DumpState* D)
 
 
 static void DumpString(const TString* s, DumpState* D)
 static void DumpString(const TString* s, DumpState* D)
 {
 {
- if (s==NULL)
- {
-  size_t size=0;
-  DumpVar(size,D);
- }
- else
- {
-  size_t size=s->tsv.len+1;		/* include trailing '\0' */
-  DumpVar(size,D);
-  DumpBlock(getstr(s),size*sizeof(char),D);
+ if (s==NULL) DumpByte(0,D);
+ else {
+  size_t size = s->tsv.len+1;  /* include trailing '\0' */
+  if (size < 0xFF) DumpByte(size,D);
+  else
+  {
+   DumpByte(0xFF,D);
+   DumpVar(size,D);
+  }
+  DumpVector(getstr(s),size-1,D);  /* no need to save '\0' */
  }
  }
 }
 }
 
 

+ 5 - 5
lundump.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lundump.c,v 2.28 2014/02/28 12:25:12 roberto Exp roberto $
+** $Id: lundump.c,v 2.29 2014/02/28 16:13:01 roberto Exp roberto $
 ** load precompiled Lua chunks
 ** load precompiled Lua chunks
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -76,15 +76,15 @@ static lua_Integer LoadInteger(LoadState* S)
 
 
 static TString* LoadString(LoadState* S)
 static TString* LoadString(LoadState* S)
 {
 {
- size_t size;
- LoadVar(S,size);
+ size_t size = LoadByte(S);
+ if (size == 0xFF) LoadVar(S,size);
  if (size==0)
  if (size==0)
   return NULL;
   return NULL;
  else
  else
  {
  {
-  char* s=luaZ_openspace(S->L,S->b,size);
+  char* s=luaZ_openspace(S->L,S->b,--size);
   LoadVector(S,s,size);
   LoadVector(S,s,size);
-  return luaS_newlstr(S->L,s,size-1);		/* remove trailing '\0' */
+  return luaS_newlstr(S->L,s,size);
  }
  }
 }
 }