"L->Mbuffbase" is better kept as offset instead of pointer
This commit is contained in:
55
lbuffer.c
55
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
|
** Auxiliary functions for building Lua libraries
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -16,70 +16,57 @@
|
|||||||
** Auxiliary buffer
|
** Auxiliary buffer
|
||||||
-------------------------------------------------------*/
|
-------------------------------------------------------*/
|
||||||
|
|
||||||
#define BUFF_STEP 32
|
|
||||||
|
|
||||||
#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
|
#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 */
|
lua_State *l = L; /* to optimize */
|
||||||
int base = l->Mbuffbase-l->Mbuffer;
|
l->Mbuffsize = l->Mbuffnext+size;
|
||||||
l->Mbuffsize *= 2;
|
l->Mbuffer = luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char,
|
||||||
if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */
|
memEM, MAX_INT);
|
||||||
l->Mbuffsize = l->Mbuffnext+size;
|
|
||||||
l->Mbuffer = luaM_realloc(l->Mbuffer, l->Mbuffsize);
|
|
||||||
l->Mbuffbase = l->Mbuffer+base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *luaL_openspace (int size)
|
char *luaL_openspace (int size) {
|
||||||
{
|
|
||||||
openspace(size);
|
openspace(size);
|
||||||
return L->Mbuffer+L->Mbuffnext;
|
return L->Mbuffer+L->Mbuffnext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaL_addchar (int c)
|
void luaL_addchar (int c) {
|
||||||
{
|
openspace(1);
|
||||||
openspace(BUFF_STEP);
|
|
||||||
L->Mbuffer[L->Mbuffnext++] = (char)c;
|
L->Mbuffer[L->Mbuffnext++] = (char)c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaL_resetbuffer (void)
|
void luaL_resetbuffer (void) {
|
||||||
{
|
L->Mbuffnext = L->Mbuffbase;
|
||||||
L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaL_addsize (int n)
|
void luaL_addsize (int n) {
|
||||||
{
|
|
||||||
L->Mbuffnext += n;
|
L->Mbuffnext += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int luaL_getsize (void)
|
int luaL_getsize (void) {
|
||||||
{
|
return L->Mbuffnext-L->Mbuffbase;
|
||||||
return L->Mbuffnext-(L->Mbuffbase-L->Mbuffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int luaL_newbuffer (int size)
|
int luaL_newbuffer (int size) {
|
||||||
{
|
int old = L->Mbuffbase;
|
||||||
int old = L->Mbuffbase-L->Mbuffer;
|
|
||||||
openspace(size);
|
openspace(size);
|
||||||
L->Mbuffbase = L->Mbuffer+L->Mbuffnext;
|
L->Mbuffbase = L->Mbuffnext;
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void luaL_oldbuffer (int old)
|
void luaL_oldbuffer (int old) {
|
||||||
{
|
L->Mbuffnext = L->Mbuffbase;
|
||||||
L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
|
L->Mbuffbase = old;
|
||||||
L->Mbuffbase = L->Mbuffer+old;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *luaL_buffer (void)
|
char *luaL_buffer (void) {
|
||||||
{
|
return L->Mbuffer+L->Mbuffbase;
|
||||||
return L->Mbuffbase;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
llex.c
14
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
|
** Lexical Analizer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -258,8 +258,8 @@ static int read_long_string (LexState *LS) {
|
|||||||
}
|
}
|
||||||
} endloop:
|
} endloop:
|
||||||
save_and_next(LS); /* skip the second ']' */
|
save_and_next(LS); /* skip the second ']' */
|
||||||
LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+2,
|
LS->seminfo.ts = luaS_newlstr(L->Mbuffer+(L->Mbuffbase+2),
|
||||||
L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-4);
|
L->Mbuffnext-L->Mbuffbase-4);
|
||||||
return STRING;
|
return STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,8 +358,8 @@ int luaX_lex (LexState *LS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
save_and_next(LS); /* skip delimiter */
|
save_and_next(LS); /* skip delimiter */
|
||||||
LS->seminfo.ts = luaS_newlstr(L->Mbuffbase+1,
|
LS->seminfo.ts = luaS_newlstr(L->Mbuffer+(L->Mbuffbase+1),
|
||||||
L->Mbuffnext-(L->Mbuffbase-L->Mbuffer)-2);
|
L->Mbuffnext-L->Mbuffbase-2);
|
||||||
return STRING;
|
return STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +401,7 @@ int luaX_lex (LexState *LS) {
|
|||||||
save_and_next(LS);
|
save_and_next(LS);
|
||||||
}
|
}
|
||||||
save('\0');
|
save('\0');
|
||||||
LS->seminfo.r = luaO_str2d(L->Mbuffbase);
|
LS->seminfo.r = luaO_str2d(L->Mbuffer+L->Mbuffbase);
|
||||||
if (LS->seminfo.r < 0)
|
if (LS->seminfo.r < 0)
|
||||||
luaX_error(LS, "invalid numeric format");
|
luaX_error(LS, "invalid numeric format");
|
||||||
return NUMBER;
|
return NUMBER;
|
||||||
@@ -425,7 +425,7 @@ int luaX_lex (LexState *LS) {
|
|||||||
save_and_next(LS);
|
save_and_next(LS);
|
||||||
} while (isalnum(LS->current) || LS->current == '_');
|
} while (isalnum(LS->current) || LS->current == '_');
|
||||||
save('\0');
|
save('\0');
|
||||||
ts = luaS_new(L->Mbuffbase);
|
ts = luaS_new(L->Mbuffer+L->Mbuffbase);
|
||||||
if (ts->head.marked >= FIRST_RESERVED)
|
if (ts->head.marked >= FIRST_RESERVED)
|
||||||
return ts->head.marked; /* reserved word */
|
return ts->head.marked; /* reserved word */
|
||||||
LS->seminfo.ts = ts;
|
LS->seminfo.ts = ts;
|
||||||
|
|||||||
4
lstate.c
4
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
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -44,7 +44,7 @@ void lua_open (void)
|
|||||||
L->refSize = 0;
|
L->refSize = 0;
|
||||||
L->Mbuffsize = 0;
|
L->Mbuffsize = 0;
|
||||||
L->Mbuffnext = 0;
|
L->Mbuffnext = 0;
|
||||||
L->Mbuffbase = NULL;
|
L->Mbuffbase = 0;
|
||||||
L->Mbuffer = NULL;
|
L->Mbuffer = NULL;
|
||||||
L->GCthreshold = GARBAGE_BLOCK;
|
L->GCthreshold = GARBAGE_BLOCK;
|
||||||
L->nblocks = 0;
|
L->nblocks = 0;
|
||||||
|
|||||||
4
lstate.h
4
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
|
** Global State
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@@ -56,7 +56,7 @@ struct lua_State {
|
|||||||
struct C_Lua_Stack Cstack; /* C2lua struct */
|
struct C_Lua_Stack Cstack; /* C2lua struct */
|
||||||
jmp_buf *errorJmp; /* current error recover point */
|
jmp_buf *errorJmp; /* current error recover point */
|
||||||
char *Mbuffer; /* global buffer */
|
char *Mbuffer; /* global buffer */
|
||||||
char *Mbuffbase; /* current first position of Mbuffer */
|
int Mbuffbase; /* current first position of Mbuffer */
|
||||||
int Mbuffsize; /* size of Mbuffer */
|
int Mbuffsize; /* size of Mbuffer */
|
||||||
int Mbuffnext; /* next position to fill in Mbuffer */
|
int Mbuffnext; /* next position to fill in Mbuffer */
|
||||||
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
|
struct C_Lua_Stack Cblocks[MAX_C_BLOCKS];
|
||||||
|
|||||||
Reference in New Issue
Block a user