Skip to content

Commit 234a6f4

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 234a6f4

File tree

2 files changed

+103
-117
lines changed

2 files changed

+103
-117
lines changed

src/pcre2_intmodedep.h

Lines changed: 25 additions & 37 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,40 +913,31 @@ 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;
934934
uint32_t c;
935-
uint32_t oc;
935+
union {
936+
uint32_t oc;
937+
#ifdef SUPPORT_UNICODE
938+
other_case_code_units occu;
939+
#endif
940+
} oc;
936941
} char_repeat;
937942

938943
struct {
@@ -979,53 +984,36 @@ typedef struct heapframe {
979984
PCRE2_SIZE length;
980985
uint32_t min;
981986
uint32_t max;
982-
uint32_t caseless;
983-
uint32_t caseopts;
984987
} ref_repeat;
985988

986989
struct {
987-
PCRE2_SPTR next_branch; /* Used only in OP_BRA handling */
988990
uint32_t frame_type; /* Set for all that use GROUPLOOP */
989991
} op_bra;
990992

991-
struct {
992-
PCRE2_SPTR next_ecode;
993-
} op_brazero;
994-
995993
struct {
996994
PCRE2_SPTR start_eptr;
997995
PCRE2_SPTR start_group;
998996
uint32_t frame_type;
999-
uint32_t matched_once;
1000-
uint32_t zero_allowed;
1001997
} op_brapos;
1002998

1003999
struct {
10041000
PCRE2_SPTR start_branch;
10051001
uint32_t frame_type;
10061002
} op_recurse;
10071003

1008-
struct {
1009-
uint32_t frame_type;
1010-
} op_assert;
1011-
10121004
struct {
10131005
PCRE2_SPTR saved_end_subject;
10141006
PCRE2_SPTR saved_eptr;
10151007
PCRE2_SIZE true_end_extra;
1016-
uint32_t frame_type;
1017-
uint32_t extra_size;
10181008
uint32_t saved_moptions;
10191009
} op_assert_scs;
10201010

10211011
struct {
10221012
PCRE2_SPTR start_branch;
10231013
PCRE2_SIZE length;
1024-
uint32_t positive;
10251014
} op_cond;
10261015

10271016
struct {
1028-
PCRE2_SPTR eptr;
10291017
uint32_t min;
10301018
uint32_t max;
10311019
} op_vreverse;

0 commit comments

Comments
 (0)