This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Move hash introspection routines into Hash::Util/Util.xs and out of universal.c
authorYves Orton <demerphq@gmail.com>
Mon, 8 Aug 2016 18:06:01 +0000 (20:06 +0200)
committerYves Orton <demerphq@gmail.com>
Sun, 14 Aug 2016 09:44:20 +0000 (11:44 +0200)
ext/Hash-Util/Util.xs
t/op/coreamp.t
t/op/each.t
t/op/hash.t
t/op/sub_lval.t
universal.c

index 611cc63..db3fb5a 100644 (file)
@@ -274,7 +274,6 @@ bucket_array(rhv)
     XSRETURN(0);
 }
 
-#if PERL_VERSION < 25
 SV*
 bucket_ratio(rhv)
         SV* rhv
@@ -284,7 +283,11 @@ bucket_ratio(rhv)
     if (SvROK(rhv)) {
         rhv= SvRV(rhv);
         if ( SvTYPE(rhv)==SVt_PVHV ) {
+#if PERL_VERSION < 25
             SV *ret= Perl_hv_scalar(aTHX_ (HV*)rhv);
+#else
+            SV *ret= Perl_hv_bucket_ratio(aTHX_ (HV*)rhv);
+#endif
             ST(0)= ret;
             XSRETURN(1);
         }
@@ -322,4 +325,3 @@ used_buckets(rhv)
     XSRETURN_UNDEF;
 }
 
-#endif
index cca23f3..5029eab 100644 (file)
@@ -14,6 +14,7 @@ BEGIN {
     $^P |= 0x100;
 }
 
+use Hash::Util;
 no warnings 'experimental::smartmatch';
 
 sub lis($$;$) {
index 0d342a2..f9adc5c 100644 (file)
@@ -5,6 +5,7 @@ BEGIN {
     @INC = '../lib';
     require './test.pl';
 }
+use Hash::Util;
 
 plan tests => 59;
 
index 3c083e0..1e5bc6d 100644 (file)
@@ -7,7 +7,7 @@ BEGIN {
 }
 
 use strict;
-
+use Hash::Util;
 # This will crash perl if it fails
 
 use constant PVBM => 'foo';
index c94e9f5..59e286c 100644 (file)
@@ -6,6 +6,7 @@ BEGIN {
     require './test.pl';
 }
 plan tests=>211;
+use Hash::Util;
 
 sub a : lvalue { my $a = 34; ${\(bless \$a)} }  # Return a temporary
 sub b : lvalue { ${\shift} }
index f0919b3..e77fad3 100644 (file)
@@ -752,68 +752,6 @@ XS(XS_PerlIO_get_layers)
     XSRETURN(0);
 }
 
-XS(XS_Hash_Util_bucket_ratio); /* prototype to pass -Wmissing-prototypes */
-XS(XS_Hash_Util_bucket_ratio)
-{
-    dXSARGS;
-    SV *rhv;
-    PERL_UNUSED_VAR(cv);
-
-    if (items != 1)
-        croak_xs_usage(cv, "hv");
-
-    rhv= ST(0);
-    if (SvROK(rhv)) {
-        rhv= SvRV(rhv);
-        if ( SvTYPE(rhv)==SVt_PVHV ) {
-            SV *ret= Perl_hv_bucket_ratio(aTHX_ (HV*)rhv);
-            ST(0)= ret;
-            XSRETURN(1);
-        }
-    }
-    XSRETURN_UNDEF;
-}
-
-XS(XS_Hash_Util_num_buckets); /* prototype to pass -Wmissing-prototypes */
-XS(XS_Hash_Util_num_buckets)
-{
-    dXSARGS;
-    SV *rhv;
-    PERL_UNUSED_VAR(cv);
-
-    if (items != 1)
-        croak_xs_usage(cv, "hv");
-
-    rhv= ST(0);
-    if (SvROK(rhv)) {
-        rhv= SvRV(rhv);
-        if ( SvTYPE(rhv)==SVt_PVHV ) {
-            XSRETURN_UV(HvMAX((HV*)rhv)+1);
-        }
-    }
-    XSRETURN_UNDEF;
-}
-
-XS(XS_Hash_Util_used_buckets); /* prototype to pass -Wmissing-prototypes */
-XS(XS_Hash_Util_used_buckets)
-{
-    dXSARGS;
-    SV *rhv;
-    PERL_UNUSED_VAR(cv);
-
-    if (items != 1)
-        croak_xs_usage(cv, "hv");
-
-    rhv= ST(0);
-    if (SvROK(rhv)) {
-        rhv= SvRV(rhv);
-        if ( SvTYPE(rhv)==SVt_PVHV ) {
-            XSRETURN_UV(HvFILL((HV*)rhv));
-        }
-    }
-    XSRETURN_UNDEF;
-}
-
 XS(XS_re_is_regexp); /* prototype to pass -Wmissing-prototypes */
 XS(XS_re_is_regexp)
 {
@@ -1066,9 +1004,6 @@ static const struct xsub_details details[] = {
     {"Internals::SvREFCNT", XS_Internals_SvREFCNT, "\\[$%@];$"},
     {"constant::_make_const", XS_constant__make_const, "\\[$@]"},
     {"PerlIO::get_layers", XS_PerlIO_get_layers, "*;@"},
-    {"Hash::Util::bucket_ratio", XS_Hash_Util_bucket_ratio, "\\%"},
-    {"Hash::Util::num_buckets", XS_Hash_Util_num_buckets, "\\%"},
-    {"Hash::Util::used_buckets", XS_Hash_Util_used_buckets, "\\%"},
     {"re::is_regexp", XS_re_is_regexp, "$"},
     {"re::regname", XS_re_regname, ";$$"},
     {"re::regnames", XS_re_regnames, ";$"},