diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-04-01 22:26:56 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-04-01 23:23:07 +0900 |
| commit | 226fcb4f2a267eb286e792812a2ca497c9d311c0 (patch) | |
| tree | 25335cf9a925f420071afa6c4b481603653669c4 /mrbgems | |
| parent | d22b72a7cc63fd4d806b0312422cdc100696fd5b (diff) | |
| download | mruby-226fcb4f2a267eb286e792812a2ca497c9d311c0.tar.gz mruby-226fcb4f2a267eb286e792812a2ca497c9d311c0.zip | |
Avoid unnecessary `nextc()` recursion.
Diffstat (limited to 'mrbgems')
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 0a5eb2a7b..6a1faf4ed 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -3967,6 +3967,27 @@ static mrb_bool peeks(parser_state *p, const char *s); static mrb_bool skips(parser_state *p, const char *s); static inline int +nextc0(parser_state *p) +{ + int c; +#ifndef MRB_DISABLE_STDIO + if (p->f) { + if (feof(p->f)) return -1; + c = fgetc(p->f); + if (c == EOF) return -1; + } + else +#endif + if (!p->s || p->s >= p->send) { + return -1; + } + else { + c = (unsigned char)*p->s++; + } + return c; +} + +static inline int nextc(parser_state *p) { int c; @@ -3980,30 +4001,18 @@ nextc(parser_state *p) cons_free(tmp); } else { -#ifndef MRB_DISABLE_STDIO - if (p->f) { - if (feof(p->f)) goto eof; - c = fgetc(p->f); - if (c == EOF) goto eof; - } - else -#endif - if (!p->s || p->s >= p->send) { - goto eof; - } - else { - c = (unsigned char)*p->s++; - } + c = nextc0(p); + if (c < 0) goto eof; } if (c >= 0) { p->column++; } if (c == '\r') { - const int lf = nextc(p); + const int lf = nextc0(p); if (lf == '\n') { return '\n'; } - pushback(p, lf); + if (lf > 0) pushback(p, lf); } return c; |
