This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Add _invlist_contains_cp
authorKarl Williamson <public@khwilliamson.com>
Mon, 23 Jul 2012 04:00:46 +0000 (22:00 -0600)
committerKarl Williamson <public@khwilliamson.com>
Wed, 25 Jul 2012 03:13:50 +0000 (21:13 -0600)
This simply searches an inversion list without going through a swash.
It will be used in a future commit.

embed.fnc
embed.h
proto.h
regcomp.c

index 0c4e5ea..dd4daef 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1052,6 +1052,7 @@ 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
+EMsR   |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 \
diff --git a/embed.h b/embed.h
index e97aa6a..f8be76d 100644 (file)
--- a/embed.h
+++ b/embed.h
 #  if defined(PERL_IN_REGCOMP_C)
 #define _append_range_to_invlist(a,b,c)        S__append_range_to_invlist(aTHX_ a,b,c)
 #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 _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)
diff --git a/proto.h b/proto.h
index c8deaf9..2c04468 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -6376,6 +6376,12 @@ PERL_STATIC_INLINE UV*   S__invlist_array_init(pTHX_ SV* const invlist, const bool
 #define PERL_ARGS_ASSERT__INVLIST_ARRAY_INIT   \
        assert(invlist)
 
+STATIC 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)
+
 STATIC SV*     S__new_invlist_C_array(pTHX_ UV* list)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(pTHX_1);
index ab9c705..8e3a837 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -7938,6 +7938,18 @@ Perl__add_range_to_invlist(pTHX_ SV* invlist, const UV start, const UV end)
 
 #endif
 
+STATIC bool
+S__invlist_contains_cp(pTHX_ SV* const invlist, const UV cp)
+{
+    /* Does <invlist> contain code point <cp> 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);