Avoid unnecessary `nextc()` recursion.

parent d22b72a7
...@@ -3967,43 +3967,52 @@ static mrb_bool peeks(parser_state *p, const char *s); ...@@ -3967,43 +3967,52 @@ static mrb_bool peeks(parser_state *p, const char *s);
static mrb_bool skips(parser_state *p, const char *s); static mrb_bool skips(parser_state *p, const char *s);
static inline int static inline int
nextc(parser_state *p) nextc0(parser_state *p)
{ {
int c; int c;
if (p->pb) {
node *tmp;
c = intn(p->pb->car);
tmp = p->pb;
p->pb = p->pb->cdr;
cons_free(tmp);
}
else {
#ifndef MRB_DISABLE_STDIO #ifndef MRB_DISABLE_STDIO
if (p->f) { if (p->f) {
if (feof(p->f)) goto eof; if (feof(p->f)) return -1;
c = fgetc(p->f); c = fgetc(p->f);
if (c == EOF) goto eof; if (c == EOF) return -1;
} }
else else
#endif #endif
if (!p->s || p->s >= p->send) { if (!p->s || p->s >= p->send) {
goto eof; return -1;
} }
else { else {
c = (unsigned char)*p->s++; c = (unsigned char)*p->s++;
} }
return c;
}
static inline int
nextc(parser_state *p)
{
int c;
if (p->pb) {
node *tmp;
c = intn(p->pb->car);
tmp = p->pb;
p->pb = p->pb->cdr;
cons_free(tmp);
}
else {
c = nextc0(p);
if (c < 0) goto eof;
} }
if (c >= 0) { if (c >= 0) {
p->column++; p->column++;
} }
if (c == '\r') { if (c == '\r') {
const int lf = nextc(p); const int lf = nextc0(p);
if (lf == '\n') { if (lf == '\n') {
return '\n'; return '\n';
} }
pushback(p, lf); if (lf > 0) pushback(p, lf);
} }
return c; return c;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment