summaryrefslogtreecommitdiff
path: root/pp_sort.c
diff options
context:
space:
mode:
authorDavid Mitchell <davem@iabyn.com>2015-12-25 22:28:14 +0000
committerDavid Mitchell <davem@iabyn.com>2016-02-03 09:19:18 +0000
commit53d3542d62a6150413de482742e24f24b82112a8 (patch)
tree3c46643591c734fd8dcbe53cbbd006280bf2ee02 /pp_sort.c
parentd77cab044d85b109271a8fd3f99e99ac1392a029 (diff)
downloadperl-53d3542d62a6150413de482742e24f24b82112a8.tar.gz
sort compare subs: don't do unnecessary scope work
The 3 functions S_sortcv(), S_sortcv_stacked(), S_sortcv_xsub(), which call a comparison function to compare $a and $b, do unnecessary work with the scope and save stacks. First, they pop any excess scope stack entries; but there shouldn't be, since exiting the sort sub should have already pooped any inner scopes. Indeed, running with an assert that PL_scopestack_ix == oldscopeix didn't trigger any failures. Secondly replace the unconditional leave_scope(oldsaveix) with LEAVE_SCOPE(), which only calls the function if PL_savestack_ix > oldsaveix.
Diffstat (limited to 'pp_sort.c')
-rw-r--r--pp_sort.c18
1 files changed, 3 insertions, 15 deletions
diff --git a/pp_sort.c b/pp_sort.c
index 8e875122f0..02c5dd8fce 100644
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -1773,7 +1773,6 @@ static I32
S_sortcv(pTHX_ SV *const a, SV *const b)
{
const I32 oldsaveix = PL_savestack_ix;
- const I32 oldscopeix = PL_scopestack_ix;
I32 result;
PMOP * const pm = PL_curpm;
COP * const cop = PL_curcop;
@@ -1791,10 +1790,7 @@ S_sortcv(pTHX_ SV *const a, SV *const b)
assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef);
result = SvIV(*PL_stack_sp);
- while (PL_scopestack_ix > oldscopeix) {
- LEAVE;
- }
- leave_scope(oldsaveix);
+ LEAVE_SCOPE(oldsaveix);
PL_curpm = pm;
return result;
}
@@ -1803,7 +1799,6 @@ static I32
S_sortcv_stacked(pTHX_ SV *const a, SV *const b)
{
const I32 oldsaveix = PL_savestack_ix;
- const I32 oldscopeix = PL_scopestack_ix;
I32 result;
AV * const av = GvAV(PL_defgv);
PMOP * const pm = PL_curpm;
@@ -1842,10 +1837,7 @@ S_sortcv_stacked(pTHX_ SV *const a, SV *const b)
assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef);
result = SvIV(*PL_stack_sp);
- while (PL_scopestack_ix > oldscopeix) {
- LEAVE;
- }
- leave_scope(oldsaveix);
+ LEAVE_SCOPE(oldsaveix);
PL_curpm = pm;
return result;
}
@@ -1855,7 +1847,6 @@ S_sortcv_xsub(pTHX_ SV *const a, SV *const b)
{
dSP;
const I32 oldsaveix = PL_savestack_ix;
- const I32 oldscopeix = PL_scopestack_ix;
CV * const cv=MUTABLE_CV(PL_sortcop);
I32 result;
PMOP * const pm = PL_curpm;
@@ -1874,10 +1865,7 @@ S_sortcv_xsub(pTHX_ SV *const a, SV *const b)
assert(PL_stack_sp > PL_stack_base || *PL_stack_base == &PL_sv_undef);
result = SvIV(*PL_stack_sp);
- while (PL_scopestack_ix > oldscopeix) {
- LEAVE;
- }
- leave_scope(oldsaveix);
+ LEAVE_SCOPE(oldsaveix);
PL_curpm = pm;
return result;
}