diff options
author | Karl Williamson <public@khwilliamson.com> | 2013-02-11 12:07:00 -0700 |
---|---|---|
committer | Karl Williamson <public@khwilliamson.com> | 2013-07-03 19:21:16 -0600 |
commit | 533c4e2f08b42d977e5004e823d4849f7473d2d0 (patch) | |
tree | b5b9d1f80b1b1069c67bc7467ea61c34ca396df1 /inline_invlist.c | |
parent | ccbd2626ed2f48a52d8b29a6c007fb3736570c9e (diff) | |
download | perl-533c4e2f08b42d977e5004e823d4849f7473d2d0.tar.gz |
regcomp.c: Add a constant 0 element before inversion lists
This commit is the first step to separating the header from the body of
inversion lists. Doing so will allow the compiled-in inversion lists to
be fully read-only.
To invert an inversion list, one simply unshifts a 0 to the front of it
if one is not there, and shifts off the 0 if it does have one.
The current data structure reserves an element at the beginning of each
inversion list that is either 0 or 1. If 0, it means the inversion list
begins there; if 1, it means the inversion list starts at the next
element. Inverting involves flipping this bit.
This commit changes the structure so that there is an additional element
just after the element that flips. This new element is always 0, and
the flipping element now says whether the inversion list begins at the
constant 0 element, or the one after that.
Doing this allows the flipping element to be separated in later commits
from the body of the inversion list, which will always begin with the
constant 0 element. That means that the body of the inversion list can
be const.
Diffstat (limited to 'inline_invlist.c')
-rw-r--r-- | inline_invlist.c | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/inline_invlist.c b/inline_invlist.c index b56ce60002..b194c0d264 100644 --- a/inline_invlist.c +++ b/inline_invlist.c @@ -20,20 +20,21 @@ * insert that at this location. Then, if an auxiliary program doesn't change * correspondingly, it will be discovered immediately */ #define INVLIST_VERSION_ID_OFFSET 3 -#define INVLIST_VERSION_ID 290655244 +#define INVLIST_VERSION_ID 1039476070 + +#define INVLIST_ZERO_OFFSET 4 /* 0 or 1 */ +/* The UV at position ZERO contains either 0 or 1. If 0, the inversion list + * contains the code point U+00000, and begins at element [0] in the array, + * which always contains 0. If 1, the inversion list doesn't contain U+0000, + * and it begins at element [1]. Inverting an inversion list consists of + * adding or removing the 0 at the beginning of it. By reserving a space for + * that 0, inversion can be made very fast: we just flip this UV */ /* For safety, when adding new elements, remember to #undef them at the end of * the inversion list code section */ -#define INVLIST_ZERO_OFFSET 4 /* 0 or 1; must be last element in header */ -/* The UV at position ZERO contains either 0 or 1. If 0, the inversion list - * contains the code point U+00000, and begins here. If 1, the inversion list - * doesn't contain U+0000, and it begins at the next UV in the array. - * Inverting an inversion list consists of adding or removing the 0 at the - * beginning of it. By reserving a space for that 0, inversion can be made - * very fast */ - -#define HEADER_LENGTH (INVLIST_ZERO_OFFSET + 1) +#define HEADER_LENGTH (INVLIST_ZERO_OFFSET + 2) /* includes 1 for the constant + 0 element */ /* An element is in an inversion list iff its index is even numbered: 0, 2, 4, * etc */ |