regcomp.c: Factor code into a function.
authorKarl Williamson <public@khwilliamson.com>
Sun, 27 Feb 2011 20:12:49 +0000 (13:12 -0700)
committerKarl Williamson <public@khwilliamson.com>
Mon, 28 Feb 2011 02:21:32 +0000 (19:21 -0700)
A future commit uses this same code, so put it into a common place.

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

index 83c6368..1a18a3a 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -981,6 +981,7 @@ Ap  |SV*    |regclass_swash |NULLOK const regexp *prog \
 #ifdef PERL_IN_REGCOMP_C
 EMi    |U8     |set_regclass_bit|NN struct RExC_state_t* pRExC_state|NN regnode* node|const U8 value|NN HV** nonbitmap_ptr
 EMs    |U8     |set_regclass_bit_fold|NN struct RExC_state_t *pRExC_state|NN regnode* node|const U8 value|NN HV** nonbitmap_ptr
+EMs    |void   |add_alternate  |NN AV** alternate_ptr|NN U8* string|STRLEN len
 #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 727e921..6aa7eb5 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define regcurly(a)            S_regcurly(aTHX_ a)
 #  endif
 #  if defined(PERL_IN_REGCOMP_C)
+#define add_alternate(a,b,c)   S_add_alternate(aTHX_ a,b,c)
 #define add_data               S_add_data
 #define add_range_to_invlist(a,b,c)    S_add_range_to_invlist(aTHX_ a,b,c)
 #define checkposixcc(a)                S_checkposixcc(aTHX_ a)
diff --git a/proto.h b/proto.h
index 9c13f8f..2faf6d5 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -5954,6 +5954,12 @@ STATIC SV *      S_space_join_names_mortal(pTHX_ char *const *array)
 
 #endif
 #if defined(PERL_IN_REGCOMP_C)
+STATIC void    S_add_alternate(pTHX_ AV** alternate_ptr, U8* string, STRLEN len)
+                       __attribute__nonnull__(pTHX_1)
+                       __attribute__nonnull__(pTHX_2);
+#define PERL_ARGS_ASSERT_ADD_ALTERNATE \
+       assert(alternate_ptr); assert(string)
+
 STATIC U32     S_add_data(struct RExC_state_t *pRExC_state, U32 n, const char *s)
                        __attribute__warn_unused_result__
                        __attribute__nonnull__(1)
index fdf96f7..a5fd3e5 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -9272,6 +9272,24 @@ S_set_regclass_bit(pTHX_ RExC_state_t *pRExC_state, regnode* node, const U8 valu
     return stored;
 }
 
+STATIC void
+S_add_alternate(pTHX_ AV** alternate_ptr, U8* string, STRLEN len)
+{
+    /* Adds input 'string' with length 'len' to the ANYOF node's unicode
+     * alternate list, pointed to by 'alternate_ptr'.  This is an array of
+     * the multi-character folds of characters in the node */
+    SV *sv;
+
+    PERL_ARGS_ASSERT_ADD_ALTERNATE;
+
+    if (! *alternate_ptr) {
+       *alternate_ptr = newAV();
+    }
+    sv = newSVpvn_utf8((char*)string, len, TRUE);
+    av_push(*alternate_ptr, sv);
+    return;
+}
+
 /*
    parse a class specification and produce either an ANYOF node that
    matches the pattern or perhaps will be optimized into an EXACTish node
@@ -9984,7 +10002,6 @@ parseit:
                         * these multicharacter foldings, to be later saved as
                         * part of the additional "s" data. */
                        if (! RExC_in_lookbehind) {
-                           SV *sv;
                            U8* loc = foldbuf;
                            U8* e = foldbuf + foldlen;
 
@@ -10019,11 +10036,7 @@ parseit:
                                }
                            }
 
-                           if (!unicode_alternate) {
-                               unicode_alternate = newAV();
-                           }
-                           sv = newSVpvn_utf8((char*)foldbuf, foldlen, TRUE);
-                           av_push(unicode_alternate, sv);
+                           add_alternate(&unicode_alternate, foldbuf, foldlen);
 
                            /* This node is variable length */
                            OP(ret) = ANYOFV;