This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Fold only use of static function into its caller
authorKarl Williamson <khw@cpan.org>
Wed, 23 Sep 2015 20:12:09 +0000 (14:12 -0600)
committerKarl Williamson <khw@cpan.org>
Sun, 11 Oct 2015 16:48:32 +0000 (10:48 -0600)
regpatws() is only used in one place, and is dangerous to retain it as a
named entity.  This is because wherever white space is to be skipped,
(#...) comments are to be as well, so the function that does both things
should be called instead of this one.

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

index 162caf2..d4f87c8 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -2162,8 +2162,6 @@ Es        |U32    |join_exact     |NN RExC_state_t *pRExC_state \
                                |NN regnode *scan|NN UV *min_subtract  \
                                |NN bool *unfolded_multi_char          \
                                |U32 flags|NULLOK regnode *val|U32 depth
-EsRn   |char * |regpatws       |NN RExC_state_t *pRExC_state \
-                               |NN char *p|const bool recognize_comment
 Ei     |void   |alloc_maybe_populate_EXACT|NN RExC_state_t *pRExC_state \
                                |NN regnode *node|NN I32 *flagp|STRLEN len \
                                |UV code_point|bool downgradable
diff --git a/embed.h b/embed.h
index 5dc4be8..5472b07 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define regex_set_precedence   S_regex_set_precedence
 #define reginsert(a,b,c,d)     S_reginsert(aTHX_ a,b,c,d)
 #define regnode_guts(a,b,c,d)  S_regnode_guts(aTHX_ a,b,c,d)
-#define regpatws               S_regpatws
 #define regpiece(a,b,c)                S_regpiece(aTHX_ a,b,c)
 #define regpposixcc(a,b,c)     S_regpposixcc(aTHX_ a,b,c)
 #define regtail(a,b,c,d)       S_regtail(aTHX_ a,b,c,d)
diff --git a/proto.h b/proto.h
index 79ad937..df82647 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -4783,11 +4783,6 @@ STATIC void      S_reginsert(pTHX_ RExC_state_t *pRExC_state, U8 op, regnode *opnd, U
 STATIC regnode*        S_regnode_guts(pTHX_ RExC_state_t *pRExC_state, const U8 op, const STRLEN extra_len, const char* const name);
 #define PERL_ARGS_ASSERT_REGNODE_GUTS  \
        assert(pRExC_state); assert(name)
-STATIC char *  S_regpatws(RExC_state_t *pRExC_state, char *p, const bool recognize_comment)
-                       __attribute__warn_unused_result__;
-#define PERL_ARGS_ASSERT_REGPATWS      \
-       assert(pRExC_state); assert(p)
-
 STATIC regnode*        S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth);
 #define PERL_ARGS_ASSERT_REGPIECE      \
        assert(pRExC_state); assert(flagp)
index 3494954..d09b00d 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -13063,29 +13063,6 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
     return(ret);
 }
 
-STATIC char *
-S_regpatws(RExC_state_t *pRExC_state, char *p , const bool recognize_comment )
-{
-    /* Returns the next non-pattern-white space, non-comment character (the
-     * latter only if 'recognize_comment is true) in the string p, which is
-     * ended by RExC_end.  See also reg_skipcomment */
-    const char *e = RExC_end;
-
-    PERL_ARGS_ASSERT_REGPATWS;
-
-    while (p < e) {
-        STRLEN len;
-       if ((len = is_PATWS_safe(p, e, UTF))) {
-           p += len;
-        }
-       else if (recognize_comment && *p == '#') {
-            p = reg_skipcomment(pRExC_state, p);
-       }
-       else
-           break;
-    }
-    return p;
-}
 
 STATIC void
 S_populate_ANYOF_from_invlist(pTHX_ regnode *node, SV** invlist_ptr)
@@ -16441,10 +16418,20 @@ S_skip_to_be_ignored_text(pTHX_ RExC_state_t *pRExC_state,
        }
 
        if (use_xmod) {
-            char * new_p = regpatws(pRExC_state, *p,
-                                    TRUE); /* means recognize comments */
-            if (new_p != *p) {
-                *p = new_p;
+            const char * save_p = *p;
+            while ((*p) < RExC_end) {
+                STRLEN len;
+                if ((len = is_PATWS_safe((*p), RExC_end, UTF))) {
+                    (*p) += len;
+                }
+                else if (*(*p) == '#') {
+                    (*p) = reg_skipcomment(pRExC_state, (*p));
+                }
+                else {
+                    break;
+                }
+            }
+            if (*p != save_p) {
                 continue;
             }
        }