]> git.vpit.fr Git - perl/modules/Sub-Nary.git/commitdiff
Rewrite count in XS. List::Util::sum isn't required anymore
authorVincent Pit <vince@profvince.com>
Fri, 8 Aug 2008 09:52:03 +0000 (11:52 +0200)
committerVincent Pit <vince@profvince.com>
Fri, 8 Aug 2008 09:52:03 +0000 (11:52 +0200)
Nary.xs
lib/Sub/Nary.pm

diff --git a/Nary.xs b/Nary.xs
index 1d6cb98db32952e097f86667f005c55c5bd3b58d..63f8cab646f7da48fb21ae1e2ef74a06f0bd6eda 100644 (file)
--- 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:
index aa2fc87359590e8ba275516f0f084291d8b90d4f..f538fc7c9eddbe327daa52c6f27630a76285b44d 100644 (file)
@@ -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;