Commit | Line | Data |
---|---|---|
d812d165 | 1 | /* inline_invlist.c |
81e983c1 KW |
2 | * |
3 | * Copyright (C) 2012 by Larry Wall and others | |
4 | * | |
5 | * You may distribute under the terms of either the GNU General Public | |
6 | * License or the Artistic License, as specified in the README file. | |
81e983c1 KW |
7 | */ |
8 | ||
9 | #if defined(PERL_IN_UTF8_C) || defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) | |
10 | ||
9e7f4f43 KW |
11 | /* An element is in an inversion list iff its index is even numbered: 0, 2, 4, |
12 | * etc */ | |
13 | #define ELEMENT_RANGE_MATCHES_INVLIST(i) (! ((i) & 1)) | |
14 | #define PREV_RANGE_MATCHES_INVLIST(i) (! ELEMENT_RANGE_MATCHES_INVLIST(i)) | |
15 | ||
d6605d24 | 16 | PERL_STATIC_INLINE STRLEN* |
9e7f4f43 KW |
17 | S__get_invlist_len_addr(pTHX_ SV* invlist) |
18 | { | |
19 | /* Return the address of the UV that contains the current number | |
20 | * of used elements in the inversion list */ | |
21 | ||
22 | PERL_ARGS_ASSERT__GET_INVLIST_LEN_ADDR; | |
23 | ||
d361b004 | 24 | return &(((XINVLIST*) SvANY(invlist))->count); |
9e7f4f43 KW |
25 | } |
26 | ||
27 | PERL_STATIC_INLINE UV | |
28 | S__invlist_len(pTHX_ SV* const invlist) | |
29 | { | |
30 | /* Returns the current number of elements stored in the inversion list's | |
31 | * array */ | |
32 | ||
33 | PERL_ARGS_ASSERT__INVLIST_LEN; | |
34 | ||
35 | return *_get_invlist_len_addr(invlist); | |
36 | } | |
37 | ||
38 | PERL_STATIC_INLINE bool | |
39 | S__invlist_contains_cp(pTHX_ SV* const invlist, const UV cp) | |
40 | { | |
41 | /* Does <invlist> contain code point <cp> as part of the set? */ | |
42 | ||
43 | IV index = _invlist_search(invlist, cp); | |
44 | ||
45 | PERL_ARGS_ASSERT__INVLIST_CONTAINS_CP; | |
46 | ||
47 | return index >= 0 && ELEMENT_RANGE_MATCHES_INVLIST(index); | |
48 | } | |
49 | ||
81e983c1 | 50 | #endif |