summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2019-02-04 15:07:11 +0000
committerDavid Mitchell <davem@iabyn.com>2019-02-05 14:03:05 +0000
commit0872de45fff4b1f6c17e1d5bec82d3d5095801a2 (patch)
treedf3784390ce43b1f7a0b401f97bde5136fe7f408
parent9b2983ca78e5369d17559ca0aa5af58e9da3724a (diff)
downloadperl-0872de45fff4b1f6c17e1d5bec82d3d5095801a2.tar.gz
Eliminate AMGf_set flag
I added this flag a few years ago when I revamped the overload macros tryAMAGICbin() etc. It allowed two different classes of macros to share the same functions (Perl_try_amagic_un/Perl_try_amagic_bin) by indicating what type of action is required. However, the last few commits have made those two functions able to robustly always determine whether its an assign-type action ($x op= $y or $lex = $x op $x) or a plain set-result-on-stack operation ($x op $y). So eliminate this flag. Note that this makes the ops which have the AMGf_set flag hard-coded infinitesimally slower, since Perl_try_amagic_bin no longer skips the checks for assign-ness. But compared with the overhead of having already called the overload method, this is is trivial. On the plus side, it makes the code smaller and easier to understand.
-rw-r--r--gv.c15
-rw-r--r--pp.c30
-rw-r--r--pp.h2
-rw-r--r--pp_hot.c2
4 files changed, 19 insertions, 30 deletions
diff --git a/gv.c b/gv.c
index 683a9f0cff..3beabe0838 100644
--- a/gv.c
+++ b/gv.c
@@ -2938,8 +2938,6 @@ Perl_gv_handler(pTHX_ HV *stash, I32 id)
/* Implement tryAMAGICun_MG macro.
Do get magic, then see if the stack arg is overloaded and if so call it.
Flags:
- AMGf_set return the arg using SETs rather than assigning to
- the targ
AMGf_numeric apply sv_2num to the stack arg.
*/
@@ -2955,10 +2953,7 @@ Perl_try_amagic_un(pTHX_ int method, int flags) {
AMGf_noright | AMGf_unary
| (flags & AMGf_numarg))))
{
- if (flags & AMGf_set) {
- SETs(tmpsv);
- }
- else {
+ {
/* where the op is of the form:
* $lex = $x op $y (where the assign is optimised away)
* then assign the returned value to targ and return that;
@@ -2988,8 +2983,6 @@ Perl_try_amagic_un(pTHX_ int method, int flags) {
Do get magic, then see if the two stack args are overloaded and if so
call it.
Flags:
- AMGf_set return the arg using SETs rather than assigning to
- the targ
AMGf_assign op may be called as mutator (eg +=)
AMGf_numeric apply sv_2num to the stack arg.
*/
@@ -3013,11 +3006,7 @@ Perl_try_amagic_bin(pTHX_ int method, int flags) {
(mutator ? AMGf_assign: 0)
| (flags & AMGf_numarg));
if (tmpsv) {
- if (flags & AMGf_set) {
- (void)POPs;
- SETs(tmpsv);
- }
- else {
+ {
(void)POPs;
/* where the op is one of the two forms:
* $x op= $y
diff --git a/pp.c b/pp.c
index 522e985931..bf93ce76cd 100644
--- a/pp.c
+++ b/pp.c
@@ -2053,7 +2053,7 @@ PP(pp_lt)
dSP;
SV *left, *right;
- tryAMAGICbin_MG(lt_amg, AMGf_set|AMGf_numeric);
+ tryAMAGICbin_MG(lt_amg, AMGf_numeric);
right = POPs;
left = TOPs;
SETs(boolSV(
@@ -2069,7 +2069,7 @@ PP(pp_gt)
dSP;
SV *left, *right;
- tryAMAGICbin_MG(gt_amg, AMGf_set|AMGf_numeric);
+ tryAMAGICbin_MG(gt_amg, AMGf_numeric);
right = POPs;
left = TOPs;
SETs(boolSV(
@@ -2085,7 +2085,7 @@ PP(pp_le)
dSP;
SV *left, *right;
- tryAMAGICbin_MG(le_amg, AMGf_set|AMGf_numeric);
+ tryAMAGICbin_MG(le_amg, AMGf_numeric);
right = POPs;
left = TOPs;
SETs(boolSV(
@@ -2101,7 +2101,7 @@ PP(pp_ge)
dSP;
SV *left, *right;
- tryAMAGICbin_MG(ge_amg, AMGf_set|AMGf_numeric);
+ tryAMAGICbin_MG(ge_amg, AMGf_numeric);
right = POPs;
left = TOPs;
SETs(boolSV(
@@ -2117,7 +2117,7 @@ PP(pp_ne)
dSP;
SV *left, *right;
- tryAMAGICbin_MG(ne_amg, AMGf_set|AMGf_numeric);
+ tryAMAGICbin_MG(ne_amg, AMGf_numeric);
right = POPs;
left = TOPs;
SETs(boolSV(
@@ -2249,7 +2249,7 @@ PP(pp_sle)
break;
}
- tryAMAGICbin_MG(amg_type, AMGf_set);
+ tryAMAGICbin_MG(amg_type, 0);
{
dPOPTOPssrl;
const int cmp =
@@ -2267,7 +2267,7 @@ PP(pp_sle)
PP(pp_seq)
{
dSP;
- tryAMAGICbin_MG(seq_amg, AMGf_set);
+ tryAMAGICbin_MG(seq_amg, 0);
{
dPOPTOPssrl;
SETs(boolSV(sv_eq_flags(left, right, 0)));
@@ -2278,7 +2278,7 @@ PP(pp_seq)
PP(pp_sne)
{
dSP;
- tryAMAGICbin_MG(sne_amg, AMGf_set);
+ tryAMAGICbin_MG(sne_amg, 0);
{
dPOPTOPssrl;
SETs(boolSV(!sv_eq_flags(left, right, 0)));
@@ -2513,7 +2513,7 @@ PP(pp_not)
dSP;
SV *sv;
- tryAMAGICun_MG(not_amg, AMGf_set);
+ tryAMAGICun_MG(not_amg, 0);
sv = *PL_stack_sp;
*PL_stack_sp = boolSV(!SvTRUE_nomg_NN(sv));
return NORMAL;
@@ -2710,7 +2710,7 @@ PP(pp_i_subtract)
PP(pp_i_lt)
{
dSP;
- tryAMAGICbin_MG(lt_amg, AMGf_set);
+ tryAMAGICbin_MG(lt_amg, 0);
{
dPOPTOPiirl_nomg;
SETs(boolSV(left < right));
@@ -2721,7 +2721,7 @@ PP(pp_i_lt)
PP(pp_i_gt)
{
dSP;
- tryAMAGICbin_MG(gt_amg, AMGf_set);
+ tryAMAGICbin_MG(gt_amg, 0);
{
dPOPTOPiirl_nomg;
SETs(boolSV(left > right));
@@ -2732,7 +2732,7 @@ PP(pp_i_gt)
PP(pp_i_le)
{
dSP;
- tryAMAGICbin_MG(le_amg, AMGf_set);
+ tryAMAGICbin_MG(le_amg, 0);
{
dPOPTOPiirl_nomg;
SETs(boolSV(left <= right));
@@ -2743,7 +2743,7 @@ PP(pp_i_le)
PP(pp_i_ge)
{
dSP;
- tryAMAGICbin_MG(ge_amg, AMGf_set);
+ tryAMAGICbin_MG(ge_amg, 0);
{
dPOPTOPiirl_nomg;
SETs(boolSV(left >= right));
@@ -2754,7 +2754,7 @@ PP(pp_i_ge)
PP(pp_i_eq)
{
dSP;
- tryAMAGICbin_MG(eq_amg, AMGf_set);
+ tryAMAGICbin_MG(eq_amg, 0);
{
dPOPTOPiirl_nomg;
SETs(boolSV(left == right));
@@ -2765,7 +2765,7 @@ PP(pp_i_eq)
PP(pp_i_ne)
{
dSP;
- tryAMAGICbin_MG(ne_amg, AMGf_set);
+ tryAMAGICbin_MG(ne_amg, 0);
{
dPOPTOPiirl_nomg;
SETs(boolSV(left != right));
diff --git a/pp.h b/pp.h
index 61e26c5dc8..98540be682 100644
--- a/pp.h
+++ b/pp.h
@@ -556,7 +556,7 @@ Does not use C<TARG>. See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
#define AMGf_assign 4 /* op supports mutator variant, e.g. $x += 1 */
#define AMGf_unary 8
#define AMGf_numeric 0x10 /* for Perl_try_amagic_bin */
-#define AMGf_set 0x20 /* for Perl_try_amagic_bin */
+
#define AMGf_want_list 0x40
#define AMGf_numarg 0x80
diff --git a/pp_hot.c b/pp_hot.c
index 39aef72f7c..fd439a5e4b 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -1257,7 +1257,7 @@ PP(pp_eq)
dSP;
SV *left, *right;
- tryAMAGICbin_MG(eq_amg, AMGf_set|AMGf_numeric);
+ tryAMAGICbin_MG(eq_amg, AMGf_numeric);
right = POPs;
left = TOPs;
SETs(boolSV(