Skip to content

Commit d6ddbd3

Browse files
committed
Fast-path ASCII identifiers constant check
1 parent 89e9040 commit d6ddbd3

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/prism.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8716,6 +8716,13 @@ lex_identifier(pm_parser_t *parser, bool previous_command_start) {
87168716
if (encoding_changed) {
87178717
return parser->encoding->isupper_char(current_start, end - current_start) ? PM_TOKEN_CONSTANT : PM_TOKEN_IDENTIFIER;
87188718
}
8719+
8720+
/* Identifiers usually start with an ASCII byte, for which the uppercase
8721+
* check is a simple range comparison. This avoids the call into the
8722+
* encoding module for every identifier. */
8723+
if (*current_start < 0x80) {
8724+
return (*current_start >= 'A' && *current_start <= 'Z') ? PM_TOKEN_CONSTANT : PM_TOKEN_IDENTIFIER;
8725+
}
87198726
return pm_encoding_utf_8_isupper_char(current_start, end - current_start) ? PM_TOKEN_CONSTANT : PM_TOKEN_IDENTIFIER;
87208727
}
87218728

0 commit comments

Comments
 (0)