This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move the aliasing of B::IV::RV as B::PV::RV from XS to Perl code.
authorNicholas Clark <nick@ccl4.org>
Sun, 7 Nov 2010 09:56:50 +0000 (09:56 +0000)
committerNicholas Clark <nick@ccl4.org>
Mon, 8 Nov 2010 07:55:09 +0000 (07:55 +0000)
This results in the same CV being used twice, rather than two CVs being created
that point to the same XS code implementation, shrinking the memory usage of B
slightly (168 bytes on this platform). It also is fewer source lines. :-)

ext/B/B.pm
ext/B/B.xs

index 587b809..773d9f1 100644 (file)
@@ -108,6 +108,13 @@ sub B::NULL::as_string() {""}
 *B::IV::as_string = \&B::IV::int_value;
 *B::PV::as_string = \&B::PV::PV;
 
+#  The input typemap checking makes no distinction between different SV types,
+#  so the XS body will generate the same C code, despite the different XS
+#  "types". So there is no change in behaviour from doing "newXS" like this,
+#  compared with the old approach of having a (near) duplicate XS body.
+#  We should fix the typemap checking.
+*B::IV::RV = \&B::PV::RV if $] > 5.012;
+
 my $debug;
 my $op_count = 0;
 my @parents = ();
index bf93317..fb450ef 100644 (file)
@@ -1564,18 +1564,6 @@ packiv(sv)
            ST(0) = newSVpvn_flags((char *)&w, 4, SVs_TEMP);
        }
 
-#if PERL_VERSION >= 11
-#  The input typemap checking makes no distinction between different SV types,
-#  so the XS body will generate the same C code, despite the different XS
-#  "types". So there is no change in behaviour from doing newXS like this,
-#  compared with the old approach of having a (near) duplicate XS body.
-#  We should fix the typemap checking.
-
-BOOT:
-        newXS("B::IV::RV", XS_B__PV_RV, __FILE__);
-
-#endif
-
 MODULE = B     PACKAGE = B::NV         PREFIX = Sv
 
 NV