From 9e7f4f43739b2597e193f775558f39082b8a213f Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Thu, 23 Aug 2012 10:36:13 -0600 Subject: [PATCH] regcomp.c: Move functions to inline_invlist.c This populates inline_invlist.c with some static inline functions and macro defines. These are the ones that are anticipated to be needed in the near term outside regcomp.c --- embed.fnc | 8 +++---- embed.h | 8 +++---- inline_invlist.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ proto.h | 48 ++++++++++++++++++++--------------------- regcomp.c | 66 ++------------------------------------------------------ 5 files changed, 98 insertions(+), 96 deletions(-) diff --git a/embed.fnc b/embed.fnc index 78308ef..f3a24b8 100644 --- a/embed.fnc +++ b/embed.fnc @@ -1054,7 +1054,6 @@ Ap |SV* |regclass_swash |NULLOK const regexp *prog \ EMs |void |add_alternate |NN AV** alternate_ptr|NN U8* string|STRLEN len EMsR |SV* |_new_invlist_C_array|NN UV* list : Not used currently: EXMs |bool |_invlistEQ |NN SV* const a|NN SV* const b|bool complement_b -EMiR |bool |_invlist_contains_cp|NN SV* const invlist|const UV cp #endif Ap |I32 |pregexec |NN REGEXP * const prog|NN char* stringarg \ |NN char* strend|NN char* strbeg|I32 minend \ @@ -1390,9 +1389,7 @@ EsM |void |_append_range_to_invlist |NN SV* const invlist|const UV start|const EiMR |UV* |_invlist_array_init |NN SV* const invlist|const bool will_have_0 EiMR |UV* |invlist_array |NN SV* const invlist EsM |void |invlist_extend |NN SV* const invlist|const UV len -EiMR |UV* |_get_invlist_len_addr |NN SV* invlist EiMR |UV* |get_invlist_zero_addr |NN SV* invlist -EiMR |UV |_invlist_len |NN SV* const invlist EiMR |UV |invlist_max |NN SV* const invlist EiM |void |invlist_set_len |NN SV* const invlist|const UV len EiM |void |invlist_trim |NN SV* const invlist @@ -1401,7 +1398,6 @@ EiMR |UV* |get_invlist_iter_addr |NN SV* invlist EiMR |UV* |get_invlist_version_id_addr |NN SV* invlist EiM |void |invlist_iterinit|NN SV* invlist EsMR |bool |invlist_iternext|NN SV* invlist|NN UV* start|NN UV* end -EXpMR |IV |_invlist_search |NN SV* const invlist|const UV cp EiMR |UV |invlist_highest|NN SV* const invlist #endif #if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_UTF8_C) @@ -1423,6 +1419,10 @@ EXp |SV* |_core_swash_init|NN const char* pkg|NN const char* name|NN SV* listsv| |I32 none|bool return_if_undef|NULLOK SV* invlist \ |bool passed_in_invlist_has_user_defined_property EXMpR |SV* |_invlist_contents|NN SV* const invlist +EiMR |UV* |_get_invlist_len_addr |NN SV* invlist +EiMR |UV |_invlist_len |NN SV* const invlist +EMiR |bool |_invlist_contains_cp|NN SV* const invlist|const UV cp +EXpMR |IV |_invlist_search |NN SV* const invlist|const UV cp EXMpR |bool |_is_swash_user_defined|NN SV* const swash EXMpR |SV* |_get_swash_invlist|NN SV* const swash #endif diff --git a/embed.h b/embed.h index 0ac80d4..3699919 100644 --- a/embed.h +++ b/embed.h @@ -901,11 +901,7 @@ # endif # if defined(PERL_IN_REGCOMP_C) #define _append_range_to_invlist(a,b,c) S__append_range_to_invlist(aTHX_ a,b,c) -#define _get_invlist_len_addr(a) S__get_invlist_len_addr(aTHX_ a) #define _invlist_array_init(a,b) S__invlist_array_init(aTHX_ a,b) -#define _invlist_contains_cp(a,b) S__invlist_contains_cp(aTHX_ a,b) -#define _invlist_len(a) S__invlist_len(aTHX_ a) -#define _invlist_search(a,b) Perl__invlist_search(aTHX_ a,b) #define _new_invlist_C_array(a) S__new_invlist_C_array(aTHX_ a) #define add_alternate(a,b,c) S_add_alternate(aTHX_ a,b,c) #define add_cp_to_invlist(a,b) S_add_cp_to_invlist(aTHX_ a,b) @@ -955,8 +951,12 @@ # endif # if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) || defined(PERL_IN_UTF8_C) #define _core_swash_init(a,b,c,d,e,f,g,h) Perl__core_swash_init(aTHX_ a,b,c,d,e,f,g,h) +#define _get_invlist_len_addr(a) S__get_invlist_len_addr(aTHX_ a) #define _get_swash_invlist(a) Perl__get_swash_invlist(aTHX_ a) +#define _invlist_contains_cp(a,b) S__invlist_contains_cp(aTHX_ a,b) #define _invlist_contents(a) Perl__invlist_contents(aTHX_ a) +#define _invlist_len(a) S__invlist_len(aTHX_ a) +#define _invlist_search(a,b) Perl__invlist_search(aTHX_ a,b) #define _is_swash_user_defined(a) Perl__is_swash_user_defined(aTHX_ a) # endif # if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_UTF8_C) diff --git a/inline_invlist.c b/inline_invlist.c index de6738f..80a6898 100644 --- a/inline_invlist.c +++ b/inline_invlist.c @@ -13,4 +13,68 @@ #if defined(PERL_IN_UTF8_C) || defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_REGEXEC_C) +#define INVLIST_LEN_OFFSET 0 /* Number of elements in the inversion list */ +#define INVLIST_ITER_OFFSET 1 /* Current iteration position */ + +/* This is a combination of a version and data structure type, so that one + * being passed in can be validated to be an inversion list of the correct + * vintage. When the structure of the header is changed, a new random number + * in the range 2**31-1 should be generated and the new() method changed to + * insert that at this location. Then, if an auxiliary program doesn't change + * correspondingly, it will be discovered immediately */ +#define INVLIST_VERSION_ID_OFFSET 2 +#define INVLIST_VERSION_ID 1064334010 + +/* For safety, when adding new elements, remember to #undef them at the end of + * the inversion list code section */ + +#define INVLIST_ZERO_OFFSET 3 /* 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) + +/* An element is in an inversion list iff its index is even numbered: 0, 2, 4, + * etc */ +#define ELEMENT_RANGE_MATCHES_INVLIST(i) (! ((i) & 1)) +#define PREV_RANGE_MATCHES_INVLIST(i) (! ELEMENT_RANGE_MATCHES_INVLIST(i)) + +PERL_STATIC_INLINE UV* +S__get_invlist_len_addr(pTHX_ SV* invlist) +{ + /* Return the address of the UV that contains the current number + * of used elements in the inversion list */ + + PERL_ARGS_ASSERT__GET_INVLIST_LEN_ADDR; + + return (UV *) (SvPVX(invlist) + (INVLIST_LEN_OFFSET * sizeof (UV))); +} + +PERL_STATIC_INLINE UV +S__invlist_len(pTHX_ SV* const invlist) +{ + /* Returns the current number of elements stored in the inversion list's + * array */ + + PERL_ARGS_ASSERT__INVLIST_LEN; + + return *_get_invlist_len_addr(invlist); +} + +PERL_STATIC_INLINE bool +S__invlist_contains_cp(pTHX_ SV* const invlist, const UV cp) +{ + /* Does contain code point as part of the set? */ + + IV index = _invlist_search(invlist, cp); + + PERL_ARGS_ASSERT__INVLIST_CONTAINS_CP; + + return index >= 0 && ELEMENT_RANGE_MATCHES_INVLIST(index); +} + #endif diff --git a/proto.h b/proto.h index 31ecc6e..d6929c7 100644 --- a/proto.h +++ b/proto.h @@ -6366,36 +6366,12 @@ STATIC void S__append_range_to_invlist(pTHX_ SV* const invlist, const UV start, #define PERL_ARGS_ASSERT__APPEND_RANGE_TO_INVLIST \ assert(invlist) -PERL_STATIC_INLINE UV* S__get_invlist_len_addr(pTHX_ SV* invlist) - __attribute__warn_unused_result__ - __attribute__nonnull__(pTHX_1); -#define PERL_ARGS_ASSERT__GET_INVLIST_LEN_ADDR \ - assert(invlist) - PERL_STATIC_INLINE UV* S__invlist_array_init(pTHX_ SV* const invlist, const bool will_have_0) __attribute__warn_unused_result__ __attribute__nonnull__(pTHX_1); #define PERL_ARGS_ASSERT__INVLIST_ARRAY_INIT \ assert(invlist) -PERL_STATIC_INLINE bool S__invlist_contains_cp(pTHX_ SV* const invlist, const UV cp) - __attribute__warn_unused_result__ - __attribute__nonnull__(pTHX_1); -#define PERL_ARGS_ASSERT__INVLIST_CONTAINS_CP \ - assert(invlist) - -PERL_STATIC_INLINE UV S__invlist_len(pTHX_ SV* const invlist) - __attribute__warn_unused_result__ - __attribute__nonnull__(pTHX_1); -#define PERL_ARGS_ASSERT__INVLIST_LEN \ - assert(invlist) - -PERL_CALLCONV IV Perl__invlist_search(pTHX_ SV* const invlist, const UV cp) - __attribute__warn_unused_result__ - __attribute__nonnull__(pTHX_1); -#define PERL_ARGS_ASSERT__INVLIST_SEARCH \ - assert(invlist) - STATIC SV* S__new_invlist_C_array(pTHX_ UV* list) __attribute__warn_unused_result__ __attribute__nonnull__(pTHX_1); @@ -6689,18 +6665,42 @@ PERL_CALLCONV SV* Perl__core_swash_init(pTHX_ const char* pkg, const char* name, #define PERL_ARGS_ASSERT__CORE_SWASH_INIT \ assert(pkg); assert(name); assert(listsv) +PERL_STATIC_INLINE UV* S__get_invlist_len_addr(pTHX_ SV* invlist) + __attribute__warn_unused_result__ + __attribute__nonnull__(pTHX_1); +#define PERL_ARGS_ASSERT__GET_INVLIST_LEN_ADDR \ + assert(invlist) + PERL_CALLCONV SV* Perl__get_swash_invlist(pTHX_ SV* const swash) __attribute__warn_unused_result__ __attribute__nonnull__(pTHX_1); #define PERL_ARGS_ASSERT__GET_SWASH_INVLIST \ assert(swash) +PERL_STATIC_INLINE bool S__invlist_contains_cp(pTHX_ SV* const invlist, const UV cp) + __attribute__warn_unused_result__ + __attribute__nonnull__(pTHX_1); +#define PERL_ARGS_ASSERT__INVLIST_CONTAINS_CP \ + assert(invlist) + PERL_CALLCONV SV* Perl__invlist_contents(pTHX_ SV* const invlist) __attribute__warn_unused_result__ __attribute__nonnull__(pTHX_1); #define PERL_ARGS_ASSERT__INVLIST_CONTENTS \ assert(invlist) +PERL_STATIC_INLINE UV S__invlist_len(pTHX_ SV* const invlist) + __attribute__warn_unused_result__ + __attribute__nonnull__(pTHX_1); +#define PERL_ARGS_ASSERT__INVLIST_LEN \ + assert(invlist) + +PERL_CALLCONV IV Perl__invlist_search(pTHX_ SV* const invlist, const UV cp) + __attribute__warn_unused_result__ + __attribute__nonnull__(pTHX_1); +#define PERL_ARGS_ASSERT__INVLIST_SEARCH \ + assert(invlist) + PERL_CALLCONV bool Perl__is_swash_user_defined(pTHX_ SV* const swash) __attribute__warn_unused_result__ __attribute__nonnull__(pTHX_1); diff --git a/regcomp.c b/regcomp.c index 9ae8294..3dcc6d9 100644 --- a/regcomp.c +++ b/regcomp.c @@ -6997,32 +6997,8 @@ S_reg_scan_name(pTHX_ RExC_state_t *pRExC_state, U32 flags) * Some of the methods should always be private to the implementation, and some * should eventually be made public */ -#define INVLIST_LEN_OFFSET 0 /* Number of elements in the inversion list */ -#define INVLIST_ITER_OFFSET 1 /* Current iteration position */ - -/* This is a combination of a version and data structure type, so that one - * being passed in can be validated to be an inversion list of the correct - * vintage. When the structure of the header is changed, a new random number - * in the range 2**31-1 should be generated and the new() method changed to - * insert that at this location. Then, if an auxiliary program doesn't change - * correspondingly, it will be discovered immediately */ -#define INVLIST_VERSION_ID_OFFSET 2 -#define INVLIST_VERSION_ID 1064334010 - -/* For safety, when adding new elements, remember to #undef them at the end of - * the inversion list code section */ - -#define INVLIST_ZERO_OFFSET 3 /* 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) - -/* Internally things are UVs */ +/* The header definitions are in F */ + #define TO_INTERNAL_SIZE(x) ((x + HEADER_LENGTH) * sizeof(UV)) #define FROM_INTERNAL_SIZE(x) ((x / sizeof(UV)) - HEADER_LENGTH) @@ -7073,27 +7049,6 @@ S_invlist_array(pTHX_ SV* const invlist) + *get_invlist_zero_addr(invlist)); } -PERL_STATIC_INLINE UV* -S__get_invlist_len_addr(pTHX_ SV* invlist) -{ - /* Return the address of the UV that contains the current number - * of used elements in the inversion list */ - - PERL_ARGS_ASSERT__GET_INVLIST_LEN_ADDR; - - return (UV *) (SvPVX(invlist) + (INVLIST_LEN_OFFSET * sizeof (UV))); -} -PERL_STATIC_INLINE UV -S__invlist_len(pTHX_ SV* const invlist) -{ - /* Returns the current number of elements stored in the inversion list's - * array */ - - PERL_ARGS_ASSERT__INVLIST_LEN; - - return *_get_invlist_len_addr(invlist); -} - PERL_STATIC_INLINE void S_invlist_set_len(pTHX_ SV* const invlist, const UV len) { @@ -7225,11 +7180,6 @@ S_invlist_trim(pTHX_ SV* const invlist) SvPV_shrink_to_cur((SV *) invlist); } -/* An element is in an inversion list iff its index is even numbered: 0, 2, 4, - * etc */ -#define ELEMENT_RANGE_MATCHES_INVLIST(i) (! ((i) & 1)) -#define PREV_RANGE_MATCHES_INVLIST(i) (! ELEMENT_RANGE_MATCHES_INVLIST(i)) - #define _invlist_union_complement_2nd(a, b, output) _invlist_union_maybe_complement_2nd(a, b, TRUE, output) STATIC void @@ -7962,18 +7912,6 @@ Perl__add_range_to_invlist(pTHX_ SV* invlist, const UV start, const UV end) #endif -PERL_STATIC_INLINE bool -S__invlist_contains_cp(pTHX_ SV* const invlist, const UV cp) -{ - /* Does contain code point as part of the set? */ - - IV index = _invlist_search(invlist, cp); - - PERL_ARGS_ASSERT__INVLIST_CONTAINS_CP; - - return index >= 0 && ELEMENT_RANGE_MATCHES_INVLIST(index); -} - PERL_STATIC_INLINE SV* S_add_cp_to_invlist(pTHX_ SV* invlist, const UV cp) { return _add_range_to_invlist(invlist, cp, cp); -- 2.7.4