[libtype-tiny-perl] 03/06: fix short-circuiting in inlined code (RT#99312)

Jonas Smedegaard dr at jones.dk
Wed Oct 29 19:42:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 1.000005
in repository libtype-tiny-perl.

commit 6e4a10ca935c987dc4c552ac4cb2f7ca596819c2
Author: Toby Inkster <mail at tobyinkster.co.uk>
Date:   Sat Oct 25 19:49:29 2014 +0100

    fix short-circuiting in inlined code (RT#99312)
---
 lib/Types/Standard/ArrayRef.pm  | 4 ++--
 lib/Types/Standard/HashRef.pm   | 2 +-
 lib/Types/Standard/Map.pm       | 8 ++++----
 lib/Types/Standard/ScalarRef.pm | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/Types/Standard/ArrayRef.pm b/lib/Types/Standard/ArrayRef.pm
index 0041ade..6ab74bc 100644
--- a/lib/Types/Standard/ArrayRef.pm
+++ b/lib/Types/Standard/ArrayRef.pm
@@ -70,7 +70,7 @@ sub __inline_generator
 		"ref($v) eq 'ARRAY' and do { "
 		.  "my \$ok = 1; "
 		.  "for my \$i (\@{$v}) { "
-		.    "\$ok = 0 && last unless $param_check "
+		.    "(\$ok = 0, last) unless $param_check "
 		.  "}; "
 		.  "\$ok "
 		."}"
@@ -110,7 +110,7 @@ sub __coercion_generator
 			my @code;
 			push @code, 'do { my ($orig, $return_orig, @new) = ($_, 0);';
 			push @code,    'for (@$orig) {';
-			push @code, sprintf('$return_orig++ && last unless (%s);', $coercable_item->inline_check('$_'));
+			push @code, sprintf('++$return_orig && last unless (%s);', $coercable_item->inline_check('$_'));
 			push @code, sprintf('push @new, (%s);', $param->coercion->inline_coercion('$_'));
 			push @code,    '}';
 			push @code,    '$return_orig ? $orig : \\@new';
diff --git a/lib/Types/Standard/HashRef.pm b/lib/Types/Standard/HashRef.pm
index 8f37a9c..1373bd1 100644
--- a/lib/Types/Standard/HashRef.pm
+++ b/lib/Types/Standard/HashRef.pm
@@ -70,7 +70,7 @@ sub __inline_generator
 		"ref($v) eq 'HASH' and do { "
 		.  "my \$ok = 1; "
 		.  "for my \$i (values \%{$v}) { "
-		.    "\$ok = 0 && last unless $param_check "
+		.    "(\$ok = 0, last) unless $param_check "
 		.  "}; "
 		.  "\$ok "
 		."}"
diff --git a/lib/Types/Standard/Map.pm b/lib/Types/Standard/Map.pm
index c25a1a0..0e21253 100644
--- a/lib/Types/Standard/Map.pm
+++ b/lib/Types/Standard/Map.pm
@@ -83,10 +83,10 @@ sub __inline_generator
 		"ref($h) eq 'HASH' and do { "
 		.  "my \$ok = 1; "
 		.  "for my \$v (values \%{$h}) { "
-		.    "\$ok = 0 && last unless $v_check "
+		.    "(\$ok = 0, last) unless $v_check "
 		.  "}; "
 		.  "for my \$k (keys \%{$h}) { "
-		.    "\$ok = 0 && last unless $k_check "
+		.    "(\$ok = 0, last) unless $k_check "
 		.  "}; "
 		.  "\$ok "
 		."}"
@@ -140,8 +140,8 @@ sub __coercion_generator
 			my @code;
 			push @code, 'do { my ($orig, $return_orig, %new) = ($_, 0);';
 			push @code,    'for (keys %$orig) {';
-			push @code, sprintf('$return_orig++ && last unless (%s);', $kcoercable_item->inline_check('$_'));
-			push @code, sprintf('$return_orig++ && last unless (%s);', $vcoercable_item->inline_check('$orig->{$_}'));
+			push @code, sprintf('++$return_orig && last unless (%s);', $kcoercable_item->inline_check('$_'));
+			push @code, sprintf('++$return_orig && last unless (%s);', $vcoercable_item->inline_check('$orig->{$_}'));
 			push @code, sprintf('$new{(%s)} = (%s);',
 				$kparam->has_coercion ? $kparam->coercion->inline_coercion('$_') : '$_',
 				$vparam->has_coercion ? $vparam->coercion->inline_coercion('$orig->{$_}') : '$orig->{$_}',
diff --git a/lib/Types/Standard/ScalarRef.pm b/lib/Types/Standard/ScalarRef.pm
index a2ded41..ff73a1a 100644
--- a/lib/Types/Standard/ScalarRef.pm
+++ b/lib/Types/Standard/ScalarRef.pm
@@ -75,7 +75,7 @@ sub __coercion_generator
 			my @code;
 			push @code, 'do { my ($orig, $return_orig, $new) = ($_, 0);';
 			push @code,    'for ($$orig) {';
-			push @code, sprintf('$return_orig++ && last unless (%s);', $coercable_item->inline_check('$_'));
+			push @code, sprintf('++$return_orig && last unless (%s);', $coercable_item->inline_check('$_'));
 			push @code, sprintf('$new = (%s);', $param->coercion->inline_coercion('$_'));
 			push @code,    '}';
 			push @code,    '$return_orig ? $orig : \\$new';

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtype-tiny-perl.git



More information about the Pkg-perl-cvs-commits mailing list