This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Extract code into separate function
authorKarl Williamson <khw@cpan.org>
Wed, 15 Aug 2018 20:02:57 +0000 (14:02 -0600)
committerKarl Williamson <khw@cpan.org>
Mon, 20 Aug 2018 18:44:25 +0000 (12:44 -0600)
This is in preparation for it to be called from a second place

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

index 6cff057..6b13840 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1710,6 +1710,7 @@ EiMn      |void   |invlist_set_previous_index|NN SV* const invlist|const IV index
 EiMRn  |IV     |invlist_previous_index|NN SV* const invlist
 EiMn   |void   |invlist_trim   |NN SV* invlist
 EiM    |void   |invlist_clear  |NN SV* invlist
+sM     |void   |initialize_invlist_guts|NN SV* invlist|const Size_t initial_size
 #endif
 EiMR   |SV*    |invlist_clone  |NN SV* const invlist
 EiMRn  |STRLEN*|get_invlist_iter_addr  |NN SV* invlist
diff --git a/embed.h b/embed.h
index bb735f3..4422f2e 100644 (file)
--- a/embed.h
+++ b/embed.h
 #define doopen_pm(a)           S_doopen_pm(aTHX_ a)
 #    endif
 #  endif
+#  if !defined(PERL_EXT_RE_BUILD)
+#    if defined(PERL_IN_REGCOMP_C)
+#define initialize_invlist_guts(a,b)   S_initialize_invlist_guts(aTHX_ a,b)
+#    endif
+#  endif
 #  if !defined(PERL_IS_MINIPERL)
 #    if defined(PERL_IN_PERL_C)
 #define incpush_if_exists(a,b,c)       S_incpush_if_exists(aTHX_ a,b,c)
diff --git a/proto.h b/proto.h
index b57762a..4cd994a 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -4165,6 +4165,9 @@ PERL_STATIC_INLINE IV*    S_get_invlist_previous_index_addr(SV* invlist)
        assert(invlist)
 #endif
 
+STATIC void    S_initialize_invlist_guts(pTHX_ SV* invlist, const Size_t initial_size);
+#define PERL_ARGS_ASSERT_INITIALIZE_INVLIST_GUTS       \
+       assert(invlist)
 #ifndef PERL_NO_INLINE_FUNCTIONS
 PERL_STATIC_INLINE void        S_invlist_clear(pTHX_ SV* invlist);
 #define PERL_ARGS_ASSERT_INVLIST_CLEAR \
index ca0c7af..199421d 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -8747,6 +8747,23 @@ S_invlist_max(SV* const invlist)
            ? FROM_INTERNAL_SIZE(SvCUR(invlist)) - 1
            : FROM_INTERNAL_SIZE(SvLEN(invlist)) - 1;
 }
+
+STATIC void
+S_initialize_invlist_guts(pTHX_ SV* invlist, const Size_t initial_size)
+{
+    PERL_ARGS_ASSERT_INITIALIZE_INVLIST_GUTS;
+
+    /* First 1 is in case the zero element isn't in the list; second 1 is for
+     * trailing NUL */
+    SvGROW(invlist, TO_INTERNAL_SIZE(initial_size + 1) + 1);
+    invlist_set_len(invlist, 0, 0);
+
+    /* Force iterinit() to be used to get iteration to work */
+    invlist_iterfinish(invlist);
+
+    *get_invlist_previous_index_addr(invlist) = 0;
+}
+
 SV*
 Perl__new_invlist(pTHX_ IV initial_size)
 {
@@ -8764,15 +8781,7 @@ Perl__new_invlist(pTHX_ IV initial_size)
     /* Allocate the initial space */
     new_list = newSV_type(SVt_INVLIST);
 
-    /* First 1 is in case the zero element isn't in the list; second 1 is for
-     * trailing NUL */
-    SvGROW(new_list, TO_INTERNAL_SIZE(initial_size + 1) + 1);
-    invlist_set_len(new_list, 0, 0);
-
-    /* Force iterinit() to be used to get iteration to work */
-    invlist_iterfinish(new_list);
-
-    *get_invlist_previous_index_addr(new_list) = 0;
+    initialize_invlist_guts(new_list, initial_size);
 
     return new_list;
 }