From: Vincent Pit Date: Fri, 8 Aug 2008 09:52:03 +0000 (+0200) Subject: Rewrite count in XS. List::Util::sum isn't required anymore X-Git-Tag: v0.03~18 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=2055b2f6d5f450e5e902c9751ddffe002ef5c8d1;p=perl%2Fmodules%2FSub-Nary.git Rewrite count in XS. List::Util::sum isn't required anymore --- diff --git a/Nary.xs b/Nary.xs index 1d6cb98..63f8cab 100644 --- a/Nary.xs +++ b/Nary.xs @@ -33,6 +33,25 @@ CODE: ST(0) = sv_2mortal(newSVuv(o == NULL)); XSRETURN(1); +void +count(SV *sv) +PROTOTYPE: $ +PREINIT: + HV *hv; + HE *key; + NV c = 0; +CODE: + if (!SvOK(sv)) + XSRETURN_IV(0); + if (!SvROK(sv)) + XSRETURN_IV(1); + hv = (HV *) SvRV(sv); + hv_iterinit(hv); + while (key = hv_iternext(hv)) { + c += SvNV(HeVAL(key)); + } + XSRETURN_NV(c); + void scalops() PROTOTYPE: diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index aa2fc87..f538fc7 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -6,7 +6,7 @@ use strict; use warnings; use Carp qw/croak/; -use List::Util qw/reduce sum/; +use List::Util qw/reduce/; use B qw/class ppname svref_2object OPf_KIDS/; @@ -192,13 +192,6 @@ sub list ($) { return $r->{list} and 1 == scalar keys %$r; } -sub count ($) { - my $r = $_[0]; - return 0 unless defined $r; - return 1 unless ref $r; - sum values %$r; -} - sub normalize ($) { my $r = $_[0]; return unless defined $r;