diff options
author | Father Chrysostomos <sprout@cpan.org> | 2012-07-14 06:58:29 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-07-14 17:35:31 -0700 |
commit | 152e8a12bd1ba6c9b17f3da2f81f37518f992ad2 (patch) | |
tree | 0a25bab0009411335281a3367dd2f352109bb498 | |
parent | c650d6974333f05db3de6fe88357fb0e710220a3 (diff) | |
download | perl-152e8a12bd1ba6c9b17f3da2f81f37518f992ad2.tar.gz |
Simplify ck_grep
Back in perl 5.000, ck_grep would call ck_sort (which was still the
case until 354dd559d99 just recently) and the latter would traverse
its way through the op_next pointers to find an op that tried to
escape the block, setting its op_next pointer to null. Then ck_grep
would traverse op_next pointers itself to find the place where ck_sort
stopped. That caused problems for grep which were fixed in 748a93069b
(perl 5.001). It was fixed by setting op_next to 0 on the first op,
so that the loop in ck_grep would not do anything. But that loop was
left there. This commit removes it.
There are also a couple of things I missed when disentangling
ck_grep and ck_sort in commit /354dd559d9. I accidentally put
if (o->op_flags & OPf_STACKED) inside if (o->op_flags & OPf_STACKED).
And the OPf_SPECIAL flag was only being set for sort’s use, so ck_grep
doesn’t need to copy that.
-rw-r--r-- | ext/B/t/f_map.t | 16 | ||||
-rw-r--r-- | ext/B/t/f_sort.t | 20 | ||||
-rw-r--r-- | ext/B/t/optree_samples.t | 4 | ||||
-rw-r--r-- | op.c | 12 |
4 files changed, 22 insertions, 30 deletions
diff --git a/ext/B/t/f_map.t b/ext/B/t/f_map.t index 4506543411..014861a412 100644 --- a/ext/B/t/f_map.t +++ b/ext/B/t/f_map.t @@ -95,7 +95,7 @@ checkOptree(note => q{}, # 3 <0> pushmark s # 4 <#> gv[*array] s # 5 <1> rv2av[t8] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t9] lK # 8 <0> enter l # 9 <;> nextstate(main 475 (eval 10):1) v:{ @@ -119,7 +119,7 @@ EOT_EOT # 3 <0> pushmark s # 4 <$> gv(*array) s # 5 <1> rv2av[t3] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t4] lK # 8 <0> enter l # 9 <;> nextstate(main 559 (eval 15):1) v:{ @@ -239,7 +239,7 @@ checkOptree(note => q{}, # 3 <0> pushmark s # 4 <#> gv[*array] s # 5 <1> rv2av[t7] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t9] lK # 8 <0> pushmark s # 9 <#> gvsv[*_] s @@ -259,7 +259,7 @@ EOT_EOT # 3 <0> pushmark s # 4 <$> gv(*array) s # 5 <1> rv2av[t4] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t5] lK # 8 <0> pushmark s # 9 <$> gvsv(*_) s @@ -291,7 +291,7 @@ checkOptree(note => q{}, # 3 <0> pushmark s # 4 <#> gv[*array] s # 5 <1> rv2av[t7] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t9] lK # 8 <0> pushmark s # 9 <#> gvsv[*_] s @@ -311,7 +311,7 @@ EOT_EOT # 3 <0> pushmark s # 4 <$> gv(*array) s # 5 <1> rv2av[t4] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t5] lK # 8 <0> pushmark s # 9 <$> gvsv(*_) s @@ -343,7 +343,7 @@ checkOptree(note => q{}, # 3 <0> pushmark s # 4 <#> gv[*array] s # 5 <1> rv2av[t6] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t8] lK # 8 <0> pushmark s # 9 <#> gvsv[*_] s @@ -362,7 +362,7 @@ EOT_EOT # 3 <0> pushmark s # 4 <$> gv(*array) s # 5 <1> rv2av[t3] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t4] lK # 8 <0> pushmark s # 9 <$> gvsv(*_) s diff --git a/ext/B/t/f_sort.t b/ext/B/t/f_sort.t index f17976f11f..fc4a009207 100644 --- a/ext/B/t/f_sort.t +++ b/ext/B/t/f_sort.t @@ -500,7 +500,7 @@ checkOptree(name => q{Compound sort/map Expression }, # 5 <0> pushmark s # 6 <#> gv[*old] s # 7 <1> rv2av[t19] lKM/1 -# 8 <@> mapstart lK* +# 8 <@> mapstart lK # 9 <|> mapwhile(other->a)[t20] lK # a <0> enter l # b <;> nextstate(main 608 (eval 34):2) v:{ @@ -513,7 +513,7 @@ checkOptree(name => q{Compound sort/map Expression }, # i <@> leave lKP # goto 9 # j <@> sort lKMS* -# k <@> mapstart lK* +# k <@> mapstart lK # l <|> mapwhile(other->m)[t26] lK # m <#> gv[*_] s # n <1> rv2sv sKM/DREFAV,1 @@ -534,7 +534,7 @@ EOT_EOT # 5 <0> pushmark s # 6 <$> gv(*old) s # 7 <1> rv2av[t10] lKM/1 -# 8 <@> mapstart lK* +# 8 <@> mapstart lK # 9 <|> mapwhile(other->a)[t11] lK # a <0> enter l # b <;> nextstate(main 608 (eval 34):2) v:{ @@ -547,7 +547,7 @@ EOT_EOT # i <@> leave lKP # goto 9 # j <@> sort lKMS* -# k <@> mapstart lK* +# k <@> mapstart lK # l <|> mapwhile(other->m)[t12] lK # m <$> gv(*_) s # n <1> rv2sv sKM/DREFAV,1 @@ -783,7 +783,7 @@ checkOptree(note => q{}, # 4 <0> pushmark s # 5 <#> gv[*input] s # 6 <1> rv2av[t9] lKM/1 -# 7 <@> grepstart lK* +# 7 <@> grepstart lK # 8 <|> grepwhile(other->9)[t10] lK # 9 <#> gvsv[*_] s # a <#> gvsv[*_] s @@ -802,7 +802,7 @@ EOT_EOT # 4 <0> pushmark s # 5 <$> gv(*input) s # 6 <1> rv2av[t3] lKM/1 -# 7 <@> grepstart lK* +# 7 <@> grepstart lK # 8 <|> grepwhile(other->9)[t4] lK # 9 <$> gvsv(*_) s # a <$> gvsv(*_) s @@ -860,7 +860,7 @@ checkOptree(note => q{}, # 3 <0> pushmark s # 4 <#> gv[*input] s # 5 <1> rv2av[t7] lKM/1 -# 6 <@> grepstart lK* +# 6 <@> grepstart lK # 7 <|> grepwhile(other->8)[t8] lK # 8 <#> gvsv[*_] s # 9 <#> gvsv[*_] s @@ -874,7 +874,7 @@ EOT_EOT # 3 <0> pushmark s # 4 <$> gv(*input) s # 5 <1> rv2av[t2] lKM/1 -# 6 <@> grepstart lK* +# 6 <@> grepstart lK # 7 <|> grepwhile(other->8)[t3] lK # 8 <$> gvsv(*_) s # 9 <$> gvsv(*_) s @@ -931,7 +931,7 @@ checkOptree(note => q{}, # 3 <0> pushmark s # 4 <#> gv[*input] s # 5 <1> rv2av[t8] lKM/1 -# 6 <@> grepstart lK* +# 6 <@> grepstart lK # 7 <|> grepwhile(other->8)[t9] lK # 8 <#> gvsv[*_] s # 9 <#> gvsv[*_] s @@ -947,7 +947,7 @@ EOT_EOT # 3 <0> pushmark s # 4 <$> gv(*input) s # 5 <1> rv2av[t2] lKM/1 -# 6 <@> grepstart lK* +# 6 <@> grepstart lK # 7 <|> grepwhile(other->8)[t3] lK # 8 <$> gvsv(*_) s # 9 <$> gvsv(*_) s diff --git a/ext/B/t/optree_samples.t b/ext/B/t/optree_samples.t index 5db514c59d..f4a6e3c74e 100644 --- a/ext/B/t/optree_samples.t +++ b/ext/B/t/optree_samples.t @@ -469,7 +469,7 @@ checkOptree ( name => '%h = map { getkey($_) => $_ } @a', # 3 <0> pushmark s # 4 <#> gv[*a] s # 5 <1> rv2av[t8] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t9] lK # 8 <0> enter l # 9 <;> nextstate(main 500 (eval 22):1) v:{ @@ -493,7 +493,7 @@ EOT_EOT # 3 <0> pushmark s # 4 <$> gv(*a) s # 5 <1> rv2av[t3] lKM/1 -# 6 <@> mapstart lK* +# 6 <@> mapstart lK # 7 <|> mapwhile(other->8)[t4] lK # 8 <0> enter l # 9 <;> nextstate(main 500 (eval 22):1) v:{ @@ -8580,20 +8580,12 @@ Perl_ck_grep(pTHX_ OP *o) /* don't allocate gwop here, as we may leak it if PL_parser->error_count > 0 */ if (o->op_flags & OPf_STACKED) { - OP* k; OP *firstkid = cLISTOPo->op_first->op_sibling; kid = cUNOPx(firstkid)->op_first; if (kid->op_type != OP_SCOPE && kid->op_type != OP_LEAVE) return no_fh_allowed(o); - if (o->op_flags & OPf_STACKED) { - LINKLIST(kid); - firstkid->op_next = kLISTOP->op_first; - kid->op_next = 0; /* just disconnect the leave/scope */ - o->op_flags |= OPf_SPECIAL; - } - for (k = kid; k; k = k->op_next) { - kid = k; - } + LINKLIST(kid); + firstkid->op_next = kLISTOP->op_first; NewOp(1101, gwop, 1, LOGOP); kid->op_next = (OP*)gwop; o->op_flags &= ~OPf_STACKED; |