[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]
unless(...) terser than if(!...)
If I write this:
$ ./perl -Ilib -MO=Concise -e 'print if !$a'
9 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v:{ ->3
- <1> null vK/1 ->9
5 <|> and(other->6) vK/1 ->9
4 <1> not sK/1 ->5
- <1> ex-rv2sv sK/1 ->4
3 <#> gvsv[*a] s ->4
8 <@> print vK ->9
6 <0> pushmark s ->7
- <1> ex-rv2sv sK/1 ->8
7 <#> gvsv[*_] s ->8
-e syntax OK
it uses one more op than the semantically equivalent:
$ ./perl -Ilib -MO=Concise -e 'print unless $a'
8 <@> leave[1 ref] vKP/REFC ->(end)
1 <0> enter ->2
2 <;> nextstate(main 1 -e:1) v:{ ->3
- <1> null vK/1 ->8
4 <|> or(other->5) vK/1 ->8
- <1> ex-rv2sv sK/1 ->4
3 <#> gvsv[*a] s ->4
7 <@> print vK ->8
5 <0> pushmark s ->6
- <1> ex-rv2sv sK/1 ->7
6 <#> gvsv[*_] s ->7
-e syntax OK
Couldn't we optimise the former to the latter fairly easily?
[I'm just not sure of the right place to do it. It strikes me that there
ought to be somewhere when the if() is being built that could spot that
the topmost op of the condition tree is not, and simply remove the not
and swap the two sides of the LOGOP. But I'm really not familiar with how
the optree generation works, so I might be completely wrong.]
Nicholas Clark
- Follow-Ups from:
-
Graham Barr <gbarr@pobox.com>
"Yitzchak Scott-Thoennes" <sthoenna@efn.org>
Vincent Pit <perl@profvince.com>
[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]