summaryrefslogtreecommitdiff
path: root/universal.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2010-10-14 11:41:50 +0100
committerNicholas Clark <nick@ccl4.org>2010-10-14 14:34:28 +0100
commit17b8ae88c658cb5fe05998ab824e6c02cfba7dcd (patch)
tree7e0f8eb8bb1c92f4a814007532b81a4cc1b792b5 /universal.c
parent451eed4a967ae47c4702ea000f3a547dc3d7267b (diff)
downloadperl-17b8ae88c658cb5fe05998ab824e6c02cfba7dcd.tar.gz
Merge XS_Tie_Hash_NamedCapture_{FIRSTK,NEXTK} into S_named_capture_iter_common.
Diffstat (limited to 'universal.c')
-rw-r--r--universal.c40
1 files changed, 13 insertions, 27 deletions
diff --git a/universal.c b/universal.c
index 5b0e5e5f61..58d00e07cc 100644
--- a/universal.c
+++ b/universal.c
@@ -1321,7 +1321,9 @@ XS(XS_Tie_Hash_NamedCapture_EXISTS)
S_named_capture_common(aTHX_ cv, FALSE, 2, FALSE, RXapif_EXISTS);
}
-XS(XS_Tie_Hash_NamedCapture_FIRSTK)
+static void
+S_named_capture_iter_common(pTHX_ CV *const cv, const int expect,
+ const U32 action)
{
dVAR;
dXSARGS;
@@ -1329,8 +1331,8 @@ XS(XS_Tie_Hash_NamedCapture_FIRSTK)
U32 flags;
SV * ret;
- if (items != 1)
- croak_xs_usage(cv, "");
+ if (items != expect)
+ croak_xs_usage(cv, expect == 2 ? "$lastkey" : "");
rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
@@ -1341,38 +1343,22 @@ XS(XS_Tie_Hash_NamedCapture_FIRSTK)
PUTBACK;
flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0))));
- ret = RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), NULL, flags | RXapif_FIRSTKEY);
+ ret = RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), expect >= 2 ? ST(1) : NULL,
+ flags | action);
SPAGAIN;
PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef);
XSRETURN(1);
}
-XS(XS_Tie_Hash_NamedCapture_NEXTK)
+XS(XS_Tie_Hash_NamedCapture_FIRSTK)
{
- dVAR;
- dXSARGS;
- REGEXP * rx;
- U32 flags;
- SV * ret;
-
- if (items != 2)
- croak_xs_usage(cv, "$lastkey");
-
- rx = PL_curpm ? PM_GETRE(PL_curpm) : NULL;
-
- if (!rx || !SvROK(ST(0)))
- XSRETURN_UNDEF;
-
- SP -= items;
- PUTBACK;
-
- flags = (U32)SvUV(SvRV(MUTABLE_SV(ST(0))));
- ret = RX_ENGINE(rx)->named_buff_iter(aTHX_ (rx), ST(1), flags | RXapif_NEXTKEY);
+ S_named_capture_iter_common(aTHX_ cv, 1, RXapif_FIRSTKEY);
+}
- SPAGAIN;
- PUSHs(ret ? sv_2mortal(ret) : &PL_sv_undef);
- XSRETURN(1);
+XS(XS_Tie_Hash_NamedCapture_NEXTK)
+{
+ S_named_capture_iter_common(aTHX_ cv, 2, RXapif_NEXTKEY);
}
XS(XS_Tie_Hash_NamedCapture_SCALAR)