From: Vincent Pit Date: Sun, 4 Sep 2011 13:03:28 +0000 (+0200) Subject: Don't grow the fake cxstack if it's already large enough X-Git-Tag: rt71212~10 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FScope-Upper.git;a=commitdiff_plain;h=ac1ed676fcda0ff05185eb9a0baded7d79af0150 Don't grow the fake cxstack if it's already large enough --- diff --git a/Upper.xs b/Upper.xs index 05d60da..fda107b 100644 --- a/Upper.xs +++ b/Upper.xs @@ -175,6 +175,8 @@ STATIC su_uplevel_ud *su_uplevel_ud_new(pTHX) { si->si_stack = newAV(); AvREAL_off(si->si_stack); si->si_cxstack = NULL; + si->si_cxmax = 0; + sud->si = si; return sud; @@ -1170,10 +1172,12 @@ STATIC I32 su_uplevel(pTHX_ CV *cv, I32 cxix, I32 args) { #endif /* Copy the context stack up to the context just below the target. */ - si->si_cxix = (cxix < 0) ? -1 : (cxix - 1); - /* The max size must be at least two so that GROW(max) = (max * 3) / 2 > max */ - si->si_cxmax = (cxix < 4) ? 4 : cxix; - Renew(si->si_cxstack, si->si_cxmax + 1, PERL_CONTEXT); + si->si_cxix = (cxix < 0) ? -1 : (cxix - 1); + if (si->si_cxmax < cxix) { + /* The max size must be at least two so that GROW(max) = (max*3)/2 > max */ + si->si_cxmax = (cxix < 4) ? 4 : cxix; + Renew(si->si_cxstack, si->si_cxmax + 1, PERL_CONTEXT); + } Copy(cur->si_cxstack, si->si_cxstack, cxix, PERL_CONTEXT); SU_POISON(si->si_cxstack + cxix, si->si_cxmax + 1 - cxix, PERL_CONTEXT);