]> git.vpit.fr Git - perl/modules/Sub-Nary.git/blobdiff - Nary.xs
Rewrite count in XS. List::Util::sum isn't required anymore
[perl/modules/Sub-Nary.git] / Nary.xs
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: