Skip to content

Commit 32b9797

Browse files
committed
9. reduce sizeof(match_context)
On 32 bit platform, 36 bytes -> 32 bytes. On 64 bit platform, 72 bytes -> 64 bytes. ctx->toplevel is used as a boolean type. ctx->jump's possible value is below: #define JUMP_NONE 0 #define JUMP_MAX_UNTIL_1 1 #define JUMP_MAX_UNTIL_2 2 #define JUMP_MAX_UNTIL_3 3 #define JUMP_MIN_UNTIL_1 4 #define JUMP_MIN_UNTIL_2 5 #define JUMP_MIN_UNTIL_3 6 #define JUMP_REPEAT 7 #define JUMP_REPEAT_ONE_1 8 #define JUMP_REPEAT_ONE_2 9 #define JUMP_MIN_REPEAT_ONE 10 #define JUMP_BRANCH 11 #define JUMP_ASSERT 12 #define JUMP_ASSERT_NOT 13
1 parent abde0e9 commit 32b9797

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Modules/sre_lib.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,6 @@ do { \
529529
DO_JUMPX(jumpvalue, jumplabel, nextpattern, 0)
530530

531531
typedef struct {
532-
Py_ssize_t last_ctx_pos;
533-
Py_ssize_t jump;
534532
SRE_CHAR* ptr;
535533
SRE_CODE* pattern;
536534
Py_ssize_t count;
@@ -540,7 +538,9 @@ typedef struct {
540538
SRE_CODE chr;
541539
SRE_REPEAT* rep;
542540
} u;
543-
int toplevel;
541+
Py_ssize_t last_ctx_pos;
542+
int8_t jump;
543+
int8_t toplevel;
544544
} SRE(match_context);
545545

546546
/* check if string matches the given pattern. returns <0 for
@@ -551,8 +551,8 @@ SRE(match)(SRE_STATE* state, SRE_CODE* pattern, int toplevel)
551551
SRE_CHAR* end = (SRE_CHAR *)state->end;
552552
Py_ssize_t alloc_pos, ctx_pos = -1;
553553
Py_ssize_t i, ret = 0;
554-
Py_ssize_t jump;
555554
unsigned int sigcount=0;
555+
int8_t jump;
556556

557557
SRE(match_context)* ctx;
558558
SRE(match_context)* nextctx;

0 commit comments

Comments
 (0)