aboutsummaryrefslogtreecommitdiff
path: root/src/lj_buf.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_buf.h')
-rw-r--r--src/lj_buf.h29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/lj_buf.h b/src/lj_buf.h
index 5a7eae31..289eb01d 100644
--- a/src/lj_buf.h
+++ b/src/lj_buf.h
@@ -14,21 +14,24 @@
14#define sbufB(sb) (mref((sb)->b, char)) 14#define sbufB(sb) (mref((sb)->b, char))
15#define sbufP(sb) (mref((sb)->p, char)) 15#define sbufP(sb) (mref((sb)->p, char))
16#define sbufE(sb) (mref((sb)->e, char)) 16#define sbufE(sb) (mref((sb)->e, char))
17#define sbufL(sb) (mref((sb)->L, lua_State))
17#define sbufsz(sb) ((MSize)(sbufE((sb)) - sbufB((sb)))) 18#define sbufsz(sb) ((MSize)(sbufE((sb)) - sbufB((sb))))
18#define sbuflen(sb) ((MSize)(sbufP((sb)) - sbufB((sb)))) 19#define sbuflen(sb) ((MSize)(sbufP((sb)) - sbufB((sb))))
19#define setsbufP(sb, q) (setmref((sb)->p, (q))) 20#define setsbufP(sb, q) (setmref((sb)->p, (q)))
21#define setsbufL(sb, l) (setmref((sb)->L, (l)))
20 22
21LJ_FUNC char *lj_buf_tmp(lua_State *L, MSize sz); 23LJ_FUNC char * LJ_FASTCALL lj_buf_tmp(lua_State *L, MSize sz);
22LJ_FUNC void lj_buf_grow(lua_State *L, SBuf *sb, char *en); 24LJ_FUNC void LJ_FASTCALL lj_buf_grow(SBuf *sb, char *en);
23LJ_FUNC void lj_buf_shrink(lua_State *L, SBuf *sb); 25LJ_FUNC void LJ_FASTCALL lj_buf_shrink(lua_State *L, SBuf *sb);
24 26
25LJ_FUNC char *lj_buf_wmem(char *p, const void *q, MSize len); 27LJ_FUNC char *lj_buf_wmem(char *p, const void *q, MSize len);
26LJ_FUNC void lj_buf_putmem(lua_State *L, SBuf *sb, const void *q, MSize len); 28LJ_FUNC void lj_buf_putmem(SBuf *sb, const void *q, MSize len);
27LJ_FUNC uint32_t lj_buf_ruleb128(const char **pp); 29LJ_FUNC uint32_t LJ_FASTCALL lj_buf_ruleb128(const char **pp);
28LJ_FUNC char *lj_buf_wuleb128(char *p, uint32_t v); 30LJ_FUNC char * LJ_FASTCALL lj_buf_wuleb128(char *p, uint32_t v);
29 31
30static LJ_AINLINE void lj_buf_init(SBuf *sb) 32static LJ_AINLINE void lj_buf_init(lua_State *L, SBuf *sb)
31{ 33{
34 setsbufL(sb, L);
32 setmref(sb->p, NULL); setmref(sb->e, NULL); setmref(sb->b, NULL); 35 setmref(sb->p, NULL); setmref(sb->e, NULL); setmref(sb->b, NULL);
33} 36}
34 37
@@ -47,25 +50,25 @@ static LJ_AINLINE GCstr *lj_buf_str(lua_State *L, SBuf *sb)
47 return lj_str_new(L, sbufB(sb), sbuflen(sb)); 50 return lj_str_new(L, sbufB(sb), sbuflen(sb));
48} 51}
49 52
50static LJ_AINLINE char *lj_buf_need(lua_State *L, SBuf *sb, MSize sz) 53static LJ_AINLINE char *lj_buf_need(SBuf *sb, MSize sz)
51{ 54{
52 char *en = sbufB(sb) + sz; 55 char *en = sbufB(sb) + sz;
53 if (LJ_UNLIKELY(en > sbufE(sb))) 56 if (LJ_UNLIKELY(en > sbufE(sb)))
54 lj_buf_grow(L, sb, en); 57 lj_buf_grow(sb, en);
55 return sbufB(sb); 58 return sbufB(sb);
56} 59}
57 60
58static LJ_AINLINE char *lj_buf_more(lua_State *L, SBuf *sb, MSize sz) 61static LJ_AINLINE char *lj_buf_more(SBuf *sb, MSize sz)
59{ 62{
60 char *en = sbufP(sb) + sz; 63 char *en = sbufP(sb) + sz;
61 if (LJ_UNLIKELY(en > sbufE(sb))) 64 if (LJ_UNLIKELY(en > sbufE(sb)))
62 lj_buf_grow(L, sb, en); 65 lj_buf_grow(sb, en);
63 return sbufP(sb); 66 return sbufP(sb);
64} 67}
65 68
66static LJ_AINLINE void lj_buf_putb(lua_State *L, SBuf *sb, int c) 69static LJ_AINLINE void lj_buf_putb(SBuf *sb, int c)
67{ 70{
68 char *p = lj_buf_more(L, sb, 1); 71 char *p = lj_buf_more(sb, 1);
69 *p++ = (char)c; 72 *p++ = (char)c;
70 setsbufP(sb, p); 73 setsbufP(sb, p);
71} 74}