]> git.vpit.fr Git - perl/modules/Sub-Nary.git/blobdiff - Nary.xs
Better be on irc.perl.org
[perl/modules/Sub-Nary.git] / Nary.xs
diff --git a/Nary.xs b/Nary.xs
index 95fca936f633ac054718d4f3ab0d9582bddcdb15..dc8e0890d3857907888a24b10925fad9ffe9138f 100644 (file)
--- a/Nary.xs
+++ b/Nary.xs
@@ -17,14 +17,12 @@ typedef struct {
 
 STATIC void sn_store(pTHX_ HV *tb, const char *key, I32 klen, SV *val, U32 hash) {
 #define sn_store(T, K, KL, V, H) sn_store(aTHX_ (T), (K), (KL), (V), (H))
- if (!hv_store(tb, key, klen, val, hash))
-  SvREFCNT_dec(val);
+ if (!hv_store(tb, key, klen, val, hash)) SvREFCNT_dec(val);
 }
 
 STATIC void sn_store_ent(pTHX_ HV *tb, SV *key, SV *val, U32 hash) {
 #define sn_store_ent(T, K, V, H) sn_store_ent(aTHX_ (T), (K), (V), (H))
- if (!hv_store_ent(tb, key, val, hash))
-  SvREFCNT_dec(val);
+ if (!hv_store_ent(tb, key, val, hash)) SvREFCNT_dec(val);
 }
 
 
@@ -142,7 +140,7 @@ CODE:
  } else {
   hv = (HV *) SvRV(sv);
   if (!hv_iterinit(hv)) {
-   sn_store(res, "0", 1, newSVnv(c), 0);
+   XSRETURN_UNDEF;
   } else {
    hv_iterinit(hv);
    while (key = hv_iternext(hv)) {
@@ -171,17 +169,11 @@ CODE:
   if (!SvOK(cur))
    continue;
   if (!SvROK(cur)) {
-   if (strEQ(SvPV_nolen(cur), "list")) {
-    hv_clear(res);
-    sn_store(res, "list", 4, newSVuv(1), sn_hash_list);
-    break;
-   } else {
-    NV v = 1;
-    if ((old = hv_fetch_ent(res, cur, 1, 0)) && SvOK(val = HeVAL(old)))
-     v += SvNV(val);
-    sn_store_ent(res, cur, newSVnv(v), 0);
-    continue;
-   }
+   NV v = 1;
+   if ((old = hv_fetch_ent(res, cur, 1, 0)) && SvOK(val = HeVAL(old)))
+    v += SvNV(val);
+   sn_store_ent(res, cur, newSVnv(v), 0);
+   continue;
   }
   cur = SvRV(cur);
   hv_iterinit((HV *) cur);
@@ -224,14 +216,18 @@ CODE:
  sv = SvRV(sv);
  if (!hv_iterinit((HV *) sv))
   XSRETURN_UNDEF;
- c = 1;
- a = c0;
- for (; n > 0; n /= 2) {
-  if (n % 2)
-   c *= a;
-  a *= a;
+ if (c0 == 1 || (SvIOK(csv) && SvIV(csv) == 1)) {
+  c = n;
+ } else {
+  c = 1;
+  a = c0;
+  for (; n > 0; n /= 2) {
+   if (n % 2)
+    c *= a;
+   a *= a;
+  }
+  c = (1 - c) / (1 - c0);
  }
- c = (1 - c) / (1 - c0);
  res = newHV();
  while (key = hv_iternext((HV *) sv)) {
   SV *k   = HeSVKEY_force(key);