lib/re1.5: Reduce code size when checking for named class char.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George 2023-01-17 17:32:53 +11:00
parent 1583c1f670
commit bd86ce5f82
1 changed files with 4 additions and 1 deletions

View File

@ -4,6 +4,9 @@
#include "re1.5.h"
// Matches: DSWdsw
#define MATCH_NAMED_CLASS_CHAR(c) (((c) | 0x20) == 'd' || ((c) | 0x24) == 'w')
#define INSERT_CODE(at, num, pc) \
((code ? memmove(code + at + num, code + at, pc - at) : 0), pc += num)
#define REL(at, to) (to - at - 2)
@ -31,7 +34,7 @@ static const char *_compilecode(const char *re, ByteProg *prog, int sizecode)
case '\\':
re++;
if (!*re) return NULL; // Trailing backslash
if ((*re | 0x20) == 'd' || (*re | 0x20) == 's' || (*re | 0x20) == 'w') {
if (MATCH_NAMED_CLASS_CHAR(*re)) {
term = PC;
EMIT(PC++, NamedClass);
EMIT(PC++, *re);