regcomp.c: Chg invlist_union() to accept NULL first param
authorKarl Williamson <public@khwilliamson.com>
Thu, 12 Jan 2012 18:09:39 +0000 (11:09 -0700)
committerKarl Williamson <public@khwilliamson.com>
Thu, 9 Feb 2012 17:13:53 +0000 (10:13 -0700)
It is common in a loop to keep adding inversion lists to a current
running total.  But the first time through, the current union list needs
to be initialized from NULL.  This puts that code in the function
instead of the callers each having to do it.

embed.fnc
proto.h
regcomp.c

index c83c0a3..68e5ecd 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1377,7 +1377,7 @@ EsMR      |IV     |invlist_search |NN SV* const invlist|const UV cp
 #endif
 #if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_UTF8_C)
 EXpM   |void   |_invlist_intersection  |NN SV* const a|NN SV* const b|NN SV** i
-EXpM   |void   |_invlist_union |NN SV* const a|NN SV* const b|NN SV** output
+EXpM   |void   |_invlist_union |NULLOK SV* const a|NN SV* const b|NN SV** output
 EXpM   |void   |_invlist_subtract|NN SV* const a|NN SV* const b|NN SV** result
 EXpM   |void   |_invlist_invert|NN SV* const invlist
 EXpM   |void   |_invlist_invert_prop|NN SV* const invlist
diff --git a/proto.h b/proto.h
index 6ac437a..6135af8 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -6581,11 +6581,10 @@ PERL_CALLCONV void      Perl__invlist_subtract(pTHX_ SV* const a, SV* const b, SV** r
        assert(a); assert(b); assert(result)
 
 PERL_CALLCONV void     Perl__invlist_union(pTHX_ SV* const a, SV* const b, SV** output)
-                       __attribute__nonnull__(pTHX_1)
                        __attribute__nonnull__(pTHX_2)
                        __attribute__nonnull__(pTHX_3);
 #define PERL_ARGS_ASSERT__INVLIST_UNION        \
-       assert(a); assert(b); assert(output)
+       assert(b); assert(output)
 
 PERL_CALLCONV SV*      Perl__new_invlist(pTHX_ IV initial_size)
                        __attribute__warn_unused_result__;
index 60c37cf..e474b30 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -6540,7 +6540,9 @@ Perl__invlist_union(pTHX_ SV* const a, SV* const b, SV** output)
 {
     /* Take the union of two inversion lists and point <output> to it.  *output
      * should be defined upon input, and if it points to one of the two lists,
-     * the reference count to that list will be decremented.
+     * the reference count to that list will be decremented.  The first list,
+     * <a>, may be NULL, in which case a copy of the second list is returned.
+     *
      * The basis for this comes from "Unicode Demystified" Chapter 13 by
      * Richard Gillam, published by Addison-Wesley, and explained at some
      * length there.  The preface says to incorporate its examples into your
@@ -6579,10 +6581,11 @@ Perl__invlist_union(pTHX_ SV* const a, SV* const b, SV** output)
     assert(a != b);
 
     /* If either one is empty, the union is the other one */
-    len_a = invlist_len(a);
-    if (len_a == 0) {
+    if (a == NULL || ((len_a = invlist_len(a)) == 0)) {
        if (*output == a) {
-           SvREFCNT_dec(a);
+            if (a != NULL) {
+                SvREFCNT_dec(a);
+            }
        }
        if (*output != b) {
            *output = invlist_clone(b);