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);