Skip to content

Commit eaa42db

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

File tree

2 files changed

+103
-117
lines changed

2 files changed

+103
-117
lines changed

src/pcre2_intmodedep.h

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,20 @@ typedef struct dfa_recursion_info {
881881
uint32_t group_num;
882882
} dfa_recursion_info;
883883

884+
#ifdef SUPPORT_UNICODE
885+
typedef struct other_case_code_units {
886+
/* Buffer for other case code units. The size of
887+
the buffer is enough to store longest character. */
888+
#if PCRE2_CODE_UNIT_WIDTH == 8
889+
PCRE2_UCHAR occu[4];
890+
#elif PCRE2_CODE_UNIT_WIDTH == 16
891+
PCRE2_UCHAR occu[2];
892+
#else
893+
PCRE2_UCHAR occu[1];
894+
#endif
895+
} other_case_code_units;
896+
#endif
897+
884898
/* Structure for "stack" frames that are used for remembering backtracking
885899
positions during matching. As these are used in a vector, with the ovector item
886900
being extended, the size of the structure must be a multiple of PCRE2_SIZE. The
@@ -899,48 +913,37 @@ typedef struct heapframe {
899913
uint32_t group_frame_type; /* Type information for group frames */
900914
uint8_t return_id; /* Where to go on in internal "return" */
901915
uint8_t op; /* Processing opcode */
916+
uint8_t byte1; /* A temporary byte to store anything */
917+
uint8_t byte2; /* A temporary byte to store anything */
902918

903-
/* At this point, the structure is 16-bit aligned. On most architectures
919+
/* At this point, the structure is 32-bit aligned. On most architectures
904920
the alignment requirement for a pointer will ensure that the eptr field below
905921
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
922+
that is 16-bit aligned, so all uint8_t members above are required for a 32
923+
bit alignment. */
922924

923925
union {
924926
/* Fields for storing localized data, which
925927
is preserved by RMATCH() calls. */
926928

927929
struct {
928-
PCRE2_SIZE length;
929-
PCRE2_SIZE oclength;
930930
PCRE2_SPTR start_eptr;
931931
PCRE2_SPTR charptr;
932932
uint32_t min;
933933
uint32_t max;
934-
uint32_t c;
935-
uint32_t oc;
934+
PCRE2_UCHAR c;
935+
PCRE2_UCHAR oc;
936+
#ifdef SUPPORT_UNICODE
937+
other_case_code_units occu;
938+
#endif
936939
} char_repeat;
937940

938941
struct {
939942
PCRE2_SPTR start_eptr;
940943
uint32_t min;
941944
uint32_t max;
942-
uint32_t c;
943-
uint32_t oc;
945+
PCRE2_UCHAR c;
946+
PCRE2_UCHAR oc;
944947
} charnot_repeat;
945948

946949
struct {
@@ -979,53 +982,36 @@ typedef struct heapframe {
979982
PCRE2_SIZE length;
980983
uint32_t min;
981984
uint32_t max;
982-
uint32_t caseless;
983-
uint32_t caseopts;
984985
} ref_repeat;
985986

986987
struct {
987-
PCRE2_SPTR next_branch; /* Used only in OP_BRA handling */
988988
uint32_t frame_type; /* Set for all that use GROUPLOOP */
989989
} op_bra;
990990

991-
struct {
992-
PCRE2_SPTR next_ecode;
993-
} op_brazero;
994-
995991
struct {
996992
PCRE2_SPTR start_eptr;
997993
PCRE2_SPTR start_group;
998994
uint32_t frame_type;
999-
uint32_t matched_once;
1000-
uint32_t zero_allowed;
1001995
} op_brapos;
1002996

1003997
struct {
1004998
PCRE2_SPTR start_branch;
1005999
uint32_t frame_type;
10061000
} op_recurse;
10071001

1008-
struct {
1009-
uint32_t frame_type;
1010-
} op_assert;
1011-
10121002
struct {
10131003
PCRE2_SPTR saved_end_subject;
10141004
PCRE2_SPTR saved_eptr;
10151005
PCRE2_SIZE true_end_extra;
1016-
uint32_t frame_type;
1017-
uint32_t extra_size;
10181006
uint32_t saved_moptions;
10191007
} op_assert_scs;
10201008

10211009
struct {
10221010
PCRE2_SPTR start_branch;
10231011
PCRE2_SIZE length;
1024-
uint32_t positive;
10251012
} op_cond;
10261013

10271014
struct {
1028-
PCRE2_SPTR eptr;
10291015
uint32_t min;
10301016
uint32_t max;
10311017
} op_vreverse;

0 commit comments

Comments
 (0)