aboutsummaryrefslogtreecommitdiff
path: root/lbuffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'lbuffer.c')
-rw-r--r--lbuffer.c55
1 files changed, 21 insertions, 34 deletions
diff --git a/lbuffer.c b/lbuffer.c
index 6bcc9c5a..b334f252 100644
--- a/lbuffer.c
+++ b/lbuffer.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbuffer.c,v 1.4 1998/06/19 16:14:09 roberto Exp roberto $ 2** $Id: lbuffer.c,v 1.5 1998/12/28 13:44:54 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -16,70 +16,57 @@
16** Auxiliary buffer 16** Auxiliary buffer
17-------------------------------------------------------*/ 17-------------------------------------------------------*/
18 18
19#define BUFF_STEP 32
20 19
21#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size) 20#define openspace(size) if (L->Mbuffnext+(size) > L->Mbuffsize) Openspace(size)
22 21
23static void Openspace (int size) 22static void Openspace (int size) {
24{
25 lua_State *l = L; /* to optimize */ 23 lua_State *l = L; /* to optimize */
26 int base = l->Mbuffbase-l->Mbuffer; 24 l->Mbuffsize = l->Mbuffnext+size;
27 l->Mbuffsize *= 2; 25 l->Mbuffer = luaM_growvector(l->Mbuffer, l->Mbuffnext, size, char,
28 if (l->Mbuffnext+size > l->Mbuffsize) /* still not big enough? */ 26 memEM, MAX_INT);
29 l->Mbuffsize = l->Mbuffnext+size;
30 l->Mbuffer = luaM_realloc(l->Mbuffer, l->Mbuffsize);
31 l->Mbuffbase = l->Mbuffer+base;
32} 27}
33 28
34 29
35char *luaL_openspace (int size) 30char *luaL_openspace (int size) {
36{
37 openspace(size); 31 openspace(size);
38 return L->Mbuffer+L->Mbuffnext; 32 return L->Mbuffer+L->Mbuffnext;
39} 33}
40 34
41 35
42void luaL_addchar (int c) 36void luaL_addchar (int c) {
43{ 37 openspace(1);
44 openspace(BUFF_STEP);
45 L->Mbuffer[L->Mbuffnext++] = (char)c; 38 L->Mbuffer[L->Mbuffnext++] = (char)c;
46} 39}
47 40
48 41
49void luaL_resetbuffer (void) 42void luaL_resetbuffer (void) {
50{ 43 L->Mbuffnext = L->Mbuffbase;
51 L->Mbuffnext = L->Mbuffbase-L->Mbuffer;
52} 44}
53 45
54 46
55void luaL_addsize (int n) 47void luaL_addsize (int n) {
56{
57 L->Mbuffnext += n; 48 L->Mbuffnext += n;
58} 49}
59 50
60int luaL_getsize (void) 51int luaL_getsize (void) {
61{ 52 return L->Mbuffnext-L->Mbuffbase;
62 return L->Mbuffnext-(L->Mbuffbase-L->Mbuffer);
63} 53}
64 54
65int luaL_newbuffer (int size) 55int luaL_newbuffer (int size) {
66{ 56 int old = L->Mbuffbase;
67 int old = L->Mbuffbase-L->Mbuffer;
68 openspace(size); 57 openspace(size);
69 L->Mbuffbase = L->Mbuffer+L->Mbuffnext; 58 L->Mbuffbase = L->Mbuffnext;
70 return old; 59 return old;
71} 60}
72 61
73 62
74void luaL_oldbuffer (int old) 63void luaL_oldbuffer (int old) {
75{ 64 L->Mbuffnext = L->Mbuffbase;
76 L->Mbuffnext = L->Mbuffbase-L->Mbuffer; 65 L->Mbuffbase = old;
77 L->Mbuffbase = L->Mbuffer+old;
78} 66}
79 67
80 68
81char *luaL_buffer (void) 69char *luaL_buffer (void) {
82{ 70 return L->Mbuffer+L->Mbuffbase;
83 return L->Mbuffbase;
84} 71}
85 72