From: Vincent Pit Date: Fri, 8 Aug 2008 10:01:54 +0000 (+0200) Subject: Rewrite zero in XS X-Git-Tag: v0.03~17 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=cb3c15c6ac05289a612b1053102fd6f7442d9a40;p=perl%2Fmodules%2FSub-Nary.git Rewrite zero in XS --- diff --git a/Nary.xs b/Nary.xs index 63f8cab..2415760 100644 --- a/Nary.xs +++ b/Nary.xs @@ -33,6 +33,23 @@ CODE: ST(0) = sv_2mortal(newSVuv(o == NULL)); XSRETURN(1); +void +zero(SV *sv) +PROTOTYPE: $ +PREINIT: + HV *hv; + IV res; +CODE: + if (!SvOK(sv)) + XSRETURN_IV(1); + if (!SvROK(sv)) { + res = SvNOK(sv) ? SvNV(sv) == 0.0 : SvUV(sv) == 0; + XSRETURN_IV(res); + } + hv = (HV *) SvRV(sv); + res = hv_exists(hv, "0", 1) && hv_iterinit(hv) == 1; + XSRETURN_IV(res); + void count(SV *sv) PROTOTYPE: $ diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index f538fc7..53aabd8 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -178,13 +178,6 @@ sub name ($) { $n eq 'null' ? substr(ppname($_[0]->targ), 3) : $n } -sub zero ($) { - my $r = $_[0]; - return 1 unless defined $r; - return $r eq '0' unless ref $r; - return $r->{0} and 1 == scalar keys %$r; -} - sub list ($) { my $r = $_[0]; return 0 unless defined $r;