Skip to content

Commit d96f139

Browse files
authored
Reduce the memory consumption of heapframe (#849)
Several local members are removed, or their size (e.g. uint32_t -> uint8_t) is reduced in heapframe.
1 parent 954a921 commit d96f139

File tree

2 files changed

+95
-117
lines changed

2 files changed

+95
-117
lines changed

src/pcre2_intmodedep.h

Lines changed: 17 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -899,40 +899,37 @@ typedef struct heapframe {
899899
uint32_t group_frame_type; /* Type information for group frames */
900900
uint8_t return_id; /* Where to go on in internal "return" */
901901
uint8_t op; /* Processing opcode */
902+
uint8_t byte1; /* A temporary byte to store anything */
903+
uint8_t byte2; /* A temporary byte to store anything */
902904

903-
/* At this point, the structure is 16-bit aligned. On most architectures
905+
/* At this point, the structure is 32-bit aligned. On most architectures
904906
the alignment requirement for a pointer will ensure that the eptr field below
905907
is 32-bit or 64-bit aligned. However, on m68k it is fine to have a pointer
906-
that is 16-bit aligned. We must therefore ensure that what comes between here
907-
and eptr is an odd multiple of 16 bits so as to get back into 32-bit
908-
alignment. This happens naturally when PCRE2_UCHAR is 8 bits wide, but needs
909-
fudges in the other cases. In the 32-bit case the padding comes first so that
910-
the occu field itself is 32-bit aligned. Without the padding, this structure
911-
is no longer a multiple of PCRE2_SIZE on m68k, and the check below fails. */
912-
913-
#if PCRE2_CODE_UNIT_WIDTH == 8
914-
PCRE2_UCHAR occu[6]; /* Used for other case code units */
915-
#elif PCRE2_CODE_UNIT_WIDTH == 16
916-
PCRE2_UCHAR occu[2]; /* Used for other case code units */
917-
uint8_t unused[2]; /* Ensure 32-bit alignment (see above) */
918-
#else
919-
uint8_t unused[2]; /* Ensure 32-bit alignment (see above) */
920-
PCRE2_UCHAR occu[1]; /* Used for other case code units */
921-
#endif
908+
that is 16-bit aligned, so all uint8_t members above are required for a 32
909+
bit alignment. */
922910

923911
union {
924912
/* Fields for storing localized data, which
925913
is preserved by RMATCH() calls. */
926914

927915
struct {
928-
PCRE2_SIZE length;
929-
PCRE2_SIZE oclength;
930916
PCRE2_SPTR start_eptr;
931917
PCRE2_SPTR charptr;
932918
uint32_t min;
933919
uint32_t max;
934920
uint32_t c;
935-
uint32_t oc;
921+
union {
922+
uint32_t oc;
923+
/* Buffer for other case code units. The size of
924+
the buffer is enough to store the longest character. */
925+
#if PCRE2_CODE_UNIT_WIDTH == 8
926+
PCRE2_UCHAR occu[4];
927+
#elif PCRE2_CODE_UNIT_WIDTH == 16
928+
PCRE2_UCHAR occu[2];
929+
#else
930+
PCRE2_UCHAR occu[1];
931+
#endif
932+
} oc;
936933
} char_repeat;
937934

938935
struct {
@@ -979,53 +976,36 @@ typedef struct heapframe {
979976
PCRE2_SIZE length;
980977
uint32_t min;
981978
uint32_t max;
982-
uint32_t caseless;
983-
uint32_t caseopts;
984979
} ref_repeat;
985980

986981
struct {
987-
PCRE2_SPTR next_branch; /* Used only in OP_BRA handling */
988982
uint32_t frame_type; /* Set for all that use GROUPLOOP */
989983
} op_bra;
990984

991-
struct {
992-
PCRE2_SPTR next_ecode;
993-
} op_brazero;
994-
995985
struct {
996986
PCRE2_SPTR start_eptr;
997987
PCRE2_SPTR start_group;
998988
uint32_t frame_type;
999-
uint32_t matched_once;
1000-
uint32_t zero_allowed;
1001989
} op_brapos;
1002990

1003991
struct {
1004992
PCRE2_SPTR start_branch;
1005993
uint32_t frame_type;
1006994
} op_recurse;
1007995

1008-
struct {
1009-
uint32_t frame_type;
1010-
} op_assert;
1011-
1012996
struct {
1013997
PCRE2_SPTR saved_end_subject;
1014998
PCRE2_SPTR saved_eptr;
1015999
PCRE2_SIZE true_end_extra;
1016-
uint32_t frame_type;
1017-
uint32_t extra_size;
10181000
uint32_t saved_moptions;
10191001
} op_assert_scs;
10201002

10211003
struct {
10221004
PCRE2_SPTR start_branch;
10231005
PCRE2_SIZE length;
1024-
uint32_t positive;
10251006
} op_cond;
10261007

10271008
struct {
1028-
PCRE2_SPTR eptr;
10291009
uint32_t min;
10301010
uint32_t max;
10311011
} op_vreverse;

0 commit comments

Comments
 (0)