From: Vincent Pit Date: Fri, 8 Aug 2008 10:05:46 +0000 (+0200) Subject: Rewrite list in XS X-Git-Tag: v0.03~16 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=2edec20dc456a6756846bbac264a99b9d6892848;p=perl%2Fmodules%2FSub-Nary.git Rewrite list in XS --- diff --git a/Nary.xs b/Nary.xs index 2415760..0165a66 100644 --- a/Nary.xs +++ b/Nary.xs @@ -50,6 +50,23 @@ CODE: res = hv_exists(hv, "0", 1) && hv_iterinit(hv) == 1; XSRETURN_IV(res); +void +list(SV *sv) +PROTOTYPE: $ +PREINIT: + HV *hv; + IV res; +CODE: + if (!SvOK(sv)) + XSRETURN_IV(0); + if (!SvROK(sv)) { + res = strEQ(SvPV_nolen(sv), "list"); + XSRETURN_IV(res); + } + hv = (HV *) SvRV(sv); + res = hv_exists(hv, "list", 4) && 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 53aabd8..6dc1820 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 list ($) { - my $r = $_[0]; - return 0 unless defined $r; - return $r eq 'list' unless ref $r; - return $r->{list} and 1 == scalar keys %$r; -} - sub normalize ($) { my $r = $_[0]; return unless defined $r;