commit 055823c04d09f6da0df1d7b5761609f749042907
parent 26d1e21c89a481c2368ba934da8e192a164d8f99
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 25 Feb 1999 12:16:39 -0300
"L->Mbuffbase" is better kept as offset instead of pointer
Diffstat:
4 files changed, 32 insertions(+), 45 deletions(-)
diff --git a/lbuffer.c b/lbuffer.c
@@ -1,5 +1,5 @@
/*
-** $Id: lbuffer.c,v 1.4 1998/06/19 16:14:09 roberto Exp roberto $
+** $Id: lbuffer.c,v 1.5 1998/12/28 13:44:54 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -16,70 +16,57 @@
** Auxiliary buffer
-------------------------------------------------------*/
-#define BUFF_STEP 32
#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
-static void Openspace (int size)
-{
+static void Openspace (int size) {
lua_State *l = L; /* to optimize */
- int base = l->Mbuffbase-l->Mbuffer;
- l->Mbuffsize *= 2;
- if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */
- l->Mbuffsize = l->Mbuffnext+size;
- l->Mbuffer = luaM_realloc(l->Mbuffer, l->Mbuffsize);
- l->Mbuffbase = l->Mbuffer+base;
+ l->Mbuffsize = l->Mbuffnext+size;
+ l->Mbuffer = luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char,
+ memEM, MAX_INT);
}
-char *luaL_openspace (int size)
-{
+char *luaL_openspace (int size) {
openspace(size);
return L->Mbuffer+L->Mbuffnext;
}
-void luaL_addchar (int c)
-{
- openspace(BUFF_STEP);
+void luaL_addchar (int c) {
+ openspace(1);
L->Mbuffer[L->Mbuffnext++] = (char)c;
}
-void luaL_resetbuffer (void)
-{
- L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
+void luaL_resetbuffer (void) {
+ L->Mbuffnext = L->Mbuffbase;
}
-void luaL_addsize (int n)
-{
+void luaL_addsize (int n) {
L->Mbuffnext += n;
}
-int luaL_getsize (void)
-{
- return L->Mbuffnext-(L->Mbuffbase-L->Mbuffer);
+int luaL_getsize (void) {
+ return L->Mbuffnext-L->Mbuffbase;
}
-int luaL_newbuffer (int size)
-{
- int old = L->Mbuffbase-L->Mbuffer;
+int luaL_newbuffer (int size) {
+ int old = L->Mbuffbase;
openspace(size);
- L->Mbuffbase = L->Mbuffer+L->Mbuffnext;
+ L->Mbuffbase = L->Mbuffnext;
return old;
}
-void luaL_oldbuffer (int old)
-{
- L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
- L->Mbuffbase = L->Mbuffer+old;
+void luaL_oldbuffer (int old) {
+ L->Mbuffnext = L->Mbuffbase;
+ L->Mbuffbase = old;
}
-char *luaL_buffer (void)
-{
- return L->Mbuffbase;
+char *luaL_buffer (void) {
+ return L->Mbuffer+L->Mbuffbase;
}
diff --git a/llex.c b/llex.c
@@ -1,5 +1,5 @@
/*
-** $Id: llex.c,v 1.27 1998/12/28 13:44:54 roberto Exp roberto $
+** $Id: llex.c,v 1.28 1999/02/04 17:47:59 roberto Exp roberto $
** Lexical Analizer
** See Copyright Notice in lua.h
*/
@@ -258,8 +258,8 @@ static int read_long_string (LexState *LS) {
}
} endloop:
save_and_next(LS); /* skip the second ']' */
- LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+2,
- L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-4);
+ LS->seminfo.ts = luaS_newlstr(L->Mbuffer+(L->Mbuffbase+2),
+ L->Mbuffnext-L->Mbuffbase-4);
return STRING;
}
@@ -358,8 +358,8 @@ int luaX_lex (LexState *LS) {
}
}
save_and_next(LS); /* skip delimiter */
- LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+1,
- L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-2);
+ LS->seminfo.ts = luaS_newlstr(L->Mbuffer+(L->Mbuffbase+1),
+ L->Mbuffnext-L->Mbuffbase-2);
return STRING;
}
@@ -401,7 +401,7 @@ int luaX_lex (LexState *LS) {
save_and_next(LS);
}
save('\0');
- LS->seminfo.r = luaO_str2d(L->Mbuffbase);
+ LS->seminfo.r = luaO_str2d(L->Mbuffer+L->Mbuffbase);
if (LS->seminfo.r < 0)
luaX_error(LS, "invalid numeric format");
return NUMBER;
@@ -425,7 +425,7 @@ int luaX_lex (LexState *LS) {
save_and_next(LS);
} while (isalnum(LS->current) || LS->current == '_');
save('\0');
- ts = luaS_new(L->Mbuffbase);
+ ts = luaS_new(L->Mbuffer+L->Mbuffbase);
if (ts->head.marked >= FIRST_RESERVED)
return ts->head.marked; /* reserved word */
LS->seminfo.ts = ts;
diff --git a/lstate.c b/lstate.c
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.c,v 1.7 1999/01/15 13:11:22 roberto Exp roberto $
+** $Id: lstate.c,v 1.8 1999/02/04 17:47:59 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -44,7 +44,7 @@ void lua_open (void)
L->refSize = 0;
L->Mbuffsize = 0;
L->Mbuffnext = 0;
- L->Mbuffbase = NULL;
+ L->Mbuffbase = 0;
L->Mbuffer = NULL;
L->GCthreshold = GARBAGE_BLOCK;
L->nblocks = 0;
diff --git a/lstate.h b/lstate.h
@@ -1,5 +1,5 @@
/*
-** $Id: lstate.h,v 1.13 1998/08/30 18:28:58 roberto Exp roberto $
+** $Id: lstate.h,v 1.14 1999/02/04 17:47:59 roberto Exp roberto $
** Global State
** See Copyright Notice in lua.h
*/
@@ -56,7 +56,7 @@ struct lua_State {
struct C_Lua_Stack Cstack; /* C2lua struct */
jmp_buf *errorJmp; /* current error recover point */
char *Mbuffer; /* global buffer */
- char *Mbuffbase; /* current first position of Mbuffer */
+ int Mbuffbase; /* current first position of Mbuffer */
int Mbuffsize; /* size of Mbuffer */
int Mbuffnext; /* next position to fill in Mbuffer */
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];