From: Salvador FandiƱo Date: Sun, 5 Jun 2005 04:25:00 +0000 (+0000) Subject: PATCH for [perl #36043] '@foo = sort { $a <=> $b } @bar' uses too much memory X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=83a44efe0f25f926e57d27d2045131cfcd0373de;p=p5sagit%2Fp5-mst-13.2.git PATCH for [perl #36043] '@foo = sort { $a <=> $b } @bar' uses too much memory Message-ID: <20050605022436.21982.qmail@lists.develooper.com> p4raw-id: //depot/perl@24708 --- diff --git a/pp_sort.c b/pp_sort.c index 349944e..203b55d 100644 --- a/pp_sort.c +++ b/pp_sort.c @@ -1593,17 +1593,40 @@ PP(pp_sort) sortsvp = S_sortsv_desc; } - /* shuffle stack down, removing optional initial cv (p1!=p2), plus any - * nulls; also stringify any args */ + /* shuffle stack down, removing optional initial cv (p1!=p2), plus + * any nulls; also stringify or converting to integer or number as + * required any args */ for (i=max; i > 0 ; i--) { if ((*p1 = *p2++)) { /* Weed out nulls. */ SvTEMP_off(*p1); - if (!PL_sortcop && !SvPOK(*p1)) { - STRLEN n_a; - if (SvAMAGIC(*p1)) - overloading = 1; - else - (void)sv_2pv(*p1, &n_a); + if (!PL_sortcop) { + if (priv & OPpSORT_NUMERIC) { + if (priv & OPpSORT_INTEGER) { + if (!SvIOK(*p1)) { + if (SvAMAGIC(*p1)) + overloading = 1; + else + (void)sv_2iv(*p1); + } + } + else { + if (!SvNOK(*p1)) { + if (SvAMAGIC(*p1)) + overloading = 1; + else + (void)sv_2nv(*p1); + } + } + } + else { + if (!SvPOK(*p1)) { + STRLEN n_a; + if (SvAMAGIC(*p1)) + overloading = 1; + else + (void)sv_2pv(*p1, &n_a); + } + } } p1++; }