From: Nicholas Clark Date: Wed, 20 Feb 2008 09:21:53 +0000 (+0000) Subject: Setting the f flag on length causes the op to be constant folded. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1518d620d80f21c46a5f3757b2ebf28b92c1d602;p=p5sagit%2Fp5-mst-13.2.git Setting the f flag on length causes the op to be constant folded. p4raw-id: //depot/perl@33337 --- diff --git a/opcode.h b/opcode.h index 82bca2d..65545a4 100644 --- a/opcode.h +++ b/opcode.h @@ -1658,7 +1658,7 @@ EXTCONST U32 PL_opargs[] = { 0x0001378e, /* hex */ 0x0001378e, /* oct */ 0x0001378e, /* abs */ - 0x0001379c, /* length */ + 0x0001379e, /* length */ 0x1322280c, /* substr */ 0x0022281c, /* vec */ 0x0122291c, /* index */ diff --git a/opcode.pl b/opcode.pl index bcbcbb0..b59af50 100755 --- a/opcode.pl +++ b/opcode.pl @@ -760,7 +760,7 @@ abs abs ck_fun fsTu% S? # String stuff. -length length ck_lengthconst isTu% S? +length length ck_lengthconst ifsTu% S? substr substr ck_substr st@ S S S? S? vec vec ck_fun ist@ S S S diff --git a/t/lib/warnings/7fatal b/t/lib/warnings/7fatal index dfbb713..6eeac74 100644 --- a/t/lib/warnings/7fatal +++ b/t/lib/warnings/7fatal @@ -285,7 +285,8 @@ time ; { use warnings FATAL => qw(void) ; - length "abc" ; + $a = "abc"; + length $a ; } join "", 1,2,3 ; @@ -293,7 +294,7 @@ join "", 1,2,3 ; print "done\n" ; EXPECT Useless use of time in void context at - line 4. -Useless use of length in void context at - line 8. +Useless use of length in void context at - line 9. ######## # TODO ? !$Config{usethreads} && $::UTF8 && ($ENV{PERL_DESTRUCT_LEVEL} || 0) > 1 ? "Parser leaks OPs, which leak shared hash keys" : '' @@ -303,7 +304,8 @@ time ; { use warnings FATAL => qw(void) ; - length "abc" ; + $a = "abc"; + length $a ; } join "", 1,2,3 ; @@ -311,7 +313,7 @@ join "", 1,2,3 ; print "done\n" ; EXPECT Useless use of time in void context at - line 4. -Useless use of length in void context at - line 8. +Useless use of length in void context at - line 9. ######## use warnings FATAL => 'all'; @@ -362,35 +364,39 @@ Use of uninitialized value $b in scalar chop at - line 7. use warnings FATAL => 'syntax', NONFATAL => 'void' ; -length "abc"; +$a = "abc"; +length $a; print STDERR "The End.\n" ; EXPECT -Useless use of length in void context at - line 4. +Useless use of length in void context at - line 5. The End. ######## use warnings FATAL => 'all', NONFATAL => 'void' ; -length "abc"; +$a = "abc"; +length $a; print STDERR "The End.\n" ; EXPECT -Useless use of length in void context at - line 4. +Useless use of length in void context at - line 5. The End. ######## use warnings FATAL => 'all', NONFATAL => 'void' ; my $a ; chomp $a; -length "abc"; + +$b = "abc" ; +length $b; print STDERR "The End.\n" ; EXPECT -Useless use of length in void context at - line 5. +Useless use of length in void context at - line 7. Use of uninitialized value $a in scalar chomp at - line 4. ######## use warnings FATAL => 'void', NONFATAL => 'void' ; - -length "abc"; +$a = "abc"; +length $a; print STDERR "The End.\n" ; EXPECT Useless use of length in void context at - line 4. @@ -399,8 +405,8 @@ The End. # TODO ? !$Config{usethreads} && $::UTF8 && ($ENV{PERL_DESTRUCT_LEVEL} || 0) > 1 ? "Parser leaks OPs, which leak shared hash keys" : '' use warnings NONFATAL => 'void', FATAL => 'void' ; - -length "abc"; +$a = "abc"; +length $a; print STDERR "The End.\n" ; EXPECT Useless use of length in void context at - line 4.