Skip to content

Commit 2a1dc79

Browse files
committed
Only dispatch to lex_optional_float_suffix when it is possible
1 parent 20e626a commit 2a1dc79

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

src/prism.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8220,11 +8220,20 @@ lex_numeric_prefix(pm_parser_t *parser, bool* seen_e) {
82208220
}
82218221

82228222
// Afterward, we'll lex as far as we can into an optional float suffix.
8223-
type = lex_optional_float_suffix(parser, seen_e);
8223+
// Guard the function call: the vast majority of decimal numbers are
8224+
// plain integers, so avoid the call when the next byte cannot start a
8225+
// float suffix.
8226+
{
8227+
uint8_t next = peek(parser);
8228+
if (next == '.' || next == 'e' || next == 'E') {
8229+
type = lex_optional_float_suffix(parser, seen_e);
82248230

8225-
// If it turned out to be a float, the cached integer value is invalid.
8226-
if (type != PM_TOKEN_INTEGER) {
8227-
parser->integer.lexed = false;
8231+
// If it turned out to be a float, the cached integer value is
8232+
// invalid.
8233+
if (type != PM_TOKEN_INTEGER) {
8234+
parser->integer.lexed = false;
8235+
}
8236+
}
82288237
}
82298238
}
82308239

0 commit comments

Comments
 (0)