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_lex.c | |
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_lex.c')
-rw-r--r-- | src/lj_lex.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/lj_lex.c b/src/lj_lex.c index 9f2b06f8..3227cadd 100644 --- a/src/lj_lex.c +++ b/src/lj_lex.c | |||
@@ -56,11 +56,9 @@ static int fillbuf(LexState *ls) | |||
56 | 56 | ||
57 | static LJ_NOINLINE void save_grow(LexState *ls, int c) | 57 | static LJ_NOINLINE void save_grow(LexState *ls, int c) |
58 | { | 58 | { |
59 | MSize newsize; | ||
60 | if (ls->sb.sz >= LJ_MAX_STR/2) | 59 | if (ls->sb.sz >= LJ_MAX_STR/2) |
61 | lj_lex_error(ls, 0, LJ_ERR_XELEM); | 60 | lj_lex_error(ls, 0, LJ_ERR_XELEM); |
62 | newsize = ls->sb.sz * 2; | 61 | lj_buf_grow(ls->L, &ls->sb, 0); |
63 | lj_str_resizebuf(ls->L, &ls->sb, newsize); | ||
64 | ls->sb.buf[ls->sb.n++] = (char)c; | 62 | ls->sb.buf[ls->sb.n++] = (char)c; |
65 | } | 63 | } |
66 | 64 | ||
@@ -167,7 +165,7 @@ static void read_long_string(LexState *ls, TValue *tv, int sep) | |||
167 | case '\r': | 165 | case '\r': |
168 | save(ls, '\n'); | 166 | save(ls, '\n'); |
169 | inclinenumber(ls); | 167 | inclinenumber(ls); |
170 | if (!tv) lj_str_resetbuf(&ls->sb); /* avoid wasting space */ | 168 | if (!tv) lj_buf_reset(&ls->sb); /* Don't waste space for comments. */ |
171 | break; | 169 | break; |
172 | default: | 170 | default: |
173 | if (tv) save_and_next(ls); | 171 | if (tv) save_and_next(ls); |
@@ -259,7 +257,7 @@ static void read_string(LexState *ls, int delim, TValue *tv) | |||
259 | 257 | ||
260 | static int llex(LexState *ls, TValue *tv) | 258 | static int llex(LexState *ls, TValue *tv) |
261 | { | 259 | { |
262 | lj_str_resetbuf(&ls->sb); | 260 | lj_buf_reset(&ls->sb); |
263 | for (;;) { | 261 | for (;;) { |
264 | if (lj_char_isident(ls->current)) { | 262 | if (lj_char_isident(ls->current)) { |
265 | GCstr *s; | 263 | GCstr *s; |
@@ -295,10 +293,10 @@ static int llex(LexState *ls, TValue *tv) | |||
295 | next(ls); | 293 | next(ls); |
296 | if (ls->current == '[') { | 294 | if (ls->current == '[') { |
297 | int sep = skip_sep(ls); | 295 | int sep = skip_sep(ls); |
298 | lj_str_resetbuf(&ls->sb); /* `skip_sep' may dirty the buffer */ | 296 | lj_buf_reset(&ls->sb); /* `skip_sep' may dirty the buffer */ |
299 | if (sep >= 0) { | 297 | if (sep >= 0) { |
300 | read_long_string(ls, NULL, sep); /* long comment */ | 298 | read_long_string(ls, NULL, sep); /* long comment */ |
301 | lj_str_resetbuf(&ls->sb); | 299 | lj_buf_reset(&ls->sb); |
302 | continue; | 300 | continue; |
303 | } | 301 | } |
304 | } | 302 | } |
@@ -381,7 +379,6 @@ int lj_lex_setup(lua_State *L, LexState *ls) | |||
381 | ls->lookahead = TK_eof; /* No look-ahead token. */ | 379 | ls->lookahead = TK_eof; /* No look-ahead token. */ |
382 | ls->linenumber = 1; | 380 | ls->linenumber = 1; |
383 | ls->lastline = 1; | 381 | ls->lastline = 1; |
384 | lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF); | ||
385 | next(ls); /* Read-ahead first char. */ | 382 | next(ls); /* Read-ahead first char. */ |
386 | if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && | 383 | if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && |
387 | char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ | 384 | char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ |
@@ -420,7 +417,7 @@ void lj_lex_cleanup(lua_State *L, LexState *ls) | |||
420 | global_State *g = G(L); | 417 | global_State *g = G(L); |
421 | lj_mem_freevec(g, ls->bcstack, ls->sizebcstack, BCInsLine); | 418 | lj_mem_freevec(g, ls->bcstack, ls->sizebcstack, BCInsLine); |
422 | lj_mem_freevec(g, ls->vstack, ls->sizevstack, VarInfo); | 419 | lj_mem_freevec(g, ls->vstack, ls->sizevstack, VarInfo); |
423 | lj_str_freebuf(g, &ls->sb); | 420 | lj_buf_free(g, &ls->sb); |
424 | } | 421 | } |
425 | 422 | ||
426 | void lj_lex_next(LexState *ls) | 423 | void lj_lex_next(LexState *ls) |