X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Nary.xs;h=dc8e0890d3857907888a24b10925fad9ffe9138f;hb=157f26dab3f210aee4c9a2d4c90230e2af3b0713;hp=95fca936f633ac054718d4f3ab0d9582bddcdb15;hpb=bb2dcaf02009e802a3a28e38915779f93d402f55;p=perl%2Fmodules%2FSub-Nary.git diff --git a/Nary.xs b/Nary.xs index 95fca93..dc8e089 100644 --- 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);