From: Nicholas Clark Date: Thu, 6 Mar 2008 11:08:24 +0000 (+0000) Subject: Refactoring the /Can't return (?:array|hash) to scalar context/ croak X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=042560a65fd56038b3116f30639cb99d98c48622;p=p5sagit%2Fp5-mst-13.2.git Refactoring the /Can't return (?:array|hash) to scalar context/ croak logic in pp_rv2av into one place saves 112 bytes here. p4raw-id: //depot/perl@33447 --- diff --git a/pp_hot.c b/pp_hot.c index 89bab4e..1dc68f0 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -801,8 +801,6 @@ PP(pp_rv2av) { dVAR; dSP; dTOPss; const I32 gimme = GIMME_V; - static const char return_array_to_lvalue_scalar[] = "Can't return array to lvalue scalar context"; - static const char return_hash_to_lvalue_scalar[] = "Can't return hash to lvalue scalar context"; static const char an_array[] = "an ARRAY"; static const char a_hash[] = "a HASH"; const bool is_pp_rv2av = PL_op->op_type == OP_RV2AV; @@ -821,8 +819,7 @@ PP(pp_rv2av) } else if (LVRET) { if (gimme != G_ARRAY) - Perl_croak(aTHX_ is_pp_rv2av ? return_array_to_lvalue_scalar - : return_hash_to_lvalue_scalar); + goto croak_cant_return; SETs(sv); RETURN; } @@ -838,9 +835,7 @@ PP(pp_rv2av) } else if (LVRET) { if (gimme != G_ARRAY) - Perl_croak(aTHX_ - is_pp_rv2av ? return_array_to_lvalue_scalar - : return_hash_to_lvalue_scalar); + goto croak_cant_return; SETs(sv); RETURN; } @@ -871,9 +866,7 @@ PP(pp_rv2av) } else if (LVRET) { if (gimme != G_ARRAY) - Perl_croak(aTHX_ - is_pp_rv2av ? return_array_to_lvalue_scalar - : return_hash_to_lvalue_scalar); + goto croak_cant_return; SETs(sv); RETURN; } @@ -923,6 +916,10 @@ PP(pp_rv2av) } } RETURN; + + croak_cant_return: + Perl_croak(aTHX_ "Can't return %s to lvalue scalar context", + is_pp_rv2av ? "array" : "hash"); } STATIC void