X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=Nary.xs;h=285bfc39973766318639023337c2f0916e90fb0f;hb=d625b2c0b187b0a423dfdcf5d96d783555bcc560;hp=bcdde48999c3c4fc881ee43c181495fe4ca9d3c7;hpb=972e76e13b6f6e85c20493bddba2d1fd71fd57f8;p=perl%2Fmodules%2FSub-Nary.git diff --git a/Nary.xs b/Nary.xs index bcdde48..285bfc3 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); } @@ -218,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);