diff options
author | Mike Pall <mike> | 2013-02-27 17:11:31 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2013-02-27 17:29:35 +0100 |
commit | 28cfcf77445e144335961a020e3e08d84cf0091f (patch) | |
tree | 1a769d0ee0fab26a79073a118ba4f9e1557b081a /src/lj_buf.h | |
parent | d44337a566bb3de06a6ac4ecf2d2a77767b86029 (diff) | |
download | luajit-28cfcf77445e144335961a020e3e08d84cf0091f.tar.gz luajit-28cfcf77445e144335961a020e3e08d84cf0091f.tar.bz2 luajit-28cfcf77445e144335961a020e3e08d84cf0091f.zip |
String buffer refactoring, part 1.
Move string buffer handling to lj_buf.*.
Use common buffer resizing function.
Diffstat (limited to 'src/lj_buf.h')
-rw-r--r-- | src/lj_buf.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lj_buf.h b/src/lj_buf.h new file mode 100644 index 00000000..19f2bb0d --- /dev/null +++ b/src/lj_buf.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | ** Buffer handling. | ||
3 | ** Copyright (C) 2005-2013 Mike Pall. See Copyright Notice in luajit.h | ||
4 | */ | ||
5 | |||
6 | #ifndef _LJ_BUF_H | ||
7 | #define _LJ_BUF_H | ||
8 | |||
9 | #include "lj_obj.h" | ||
10 | |||
11 | /* Resizable string buffers. Struct definition in lj_obj.h. */ | ||
12 | LJ_FUNC char *lj_buf_tmp(lua_State *L, MSize sz); | ||
13 | LJ_FUNC void lj_buf_grow(lua_State *L, SBuf *sb, MSize sz); | ||
14 | LJ_FUNC void lj_buf_shrink(lua_State *L, SBuf *sb); | ||
15 | |||
16 | #define lj_buf_init(sb) ((sb)->buf = NULL, (sb)->sz = 0) | ||
17 | #define lj_buf_reset(sb) ((sb)->n = 0) | ||
18 | #define lj_buf_free(g, sb) lj_mem_free(g, (void *)(sb)->buf, (sb)->sz) | ||
19 | |||
20 | static LJ_AINLINE char *lj_buf_need(lua_State *L, SBuf *sb, MSize sz) | ||
21 | { | ||
22 | if (LJ_UNLIKELY(sz > sb->sz)) | ||
23 | lj_buf_grow(L, sb, sz); | ||
24 | return sb->buf; | ||
25 | } | ||
26 | |||
27 | #endif | ||