diff options
author | Andy Lester <andy@petdance.com> | 2006-03-30 17:42:28 -0600 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2006-03-31 12:30:31 +0000 |
commit | d4c19fe8d8a6e04364af0548bf783e83ab5987d2 (patch) | |
tree | 99c9bda0de1d3d3b176a6b6ec8387cbc8002e990 /pp_sort.c | |
parent | 4d91e28241ad974dc4df24b1f21b7278e74f5310 (diff) | |
download | perl-d4c19fe8d8a6e04364af0548bf783e83ab5987d2.tar.gz |
Random accumulated patches
Message-ID: <20060331054228.GA18940@petdance.com>
p4raw-id: //depot/perl@27641
Diffstat (limited to 'pp_sort.c')
-rw-r--r-- | pp_sort.c | 33 |
1 files changed, 17 insertions, 16 deletions
@@ -180,12 +180,11 @@ typedef SV * gptr; /* pointers in our lists */ static IV -dynprep(pTHX_ gptr *list1, gptr *list2, size_t nmemb, SVCOMPARE_t cmp) +dynprep(pTHX_ gptr *list1, gptr *list2, size_t nmemb, const SVCOMPARE_t cmp) { I32 sense; register gptr *b, *p, *q, *t, *p2; - register gptr c, *last, *r; - gptr *savep; + register gptr *last, *r; IV runs = 0; b = list1; @@ -217,7 +216,8 @@ dynprep(pTHX_ gptr *list1, gptr *list2, size_t nmemb, SVCOMPARE_t cmp) } } if (q > b) { /* run of greater than 2 at b */ - savep = p; + gptr *savep = p; + p = q += 2; /* pick up singleton, if possible */ if ((p == t) && @@ -225,17 +225,18 @@ dynprep(pTHX_ gptr *list1, gptr *list2, size_t nmemb, SVCOMPARE_t cmp) ((cmp(aTHX_ *(p-1), *p) > 0) == sense)) savep = r = p = q = last; p2 = NEXT(p2) = p2 + (p - b); ++runs; - if (sense) while (b < --p) { - c = *b; - *b++ = *p; - *p = c; - } + if (sense) + while (b < --p) { + const gptr c = *b; + *b++ = *p; + *p = c; + } p = savep; } while (q < p) { /* simple pairs */ p2 = NEXT(p2) = p2 + 2; ++runs; if (sense) { - c = *q++; + const gptr c = *q++; *(q-1) = *q; *q++ = c; } else q += 2; @@ -358,7 +359,7 @@ S_mergesortsv(pTHX_ gptr *base, size_t nmemb, SVCOMPARE_t cmp, U32 flags) gptr small[SMALLSORT]; gptr *which[3]; off_runs stack[60], *stackp; - SVCOMPARE_t savecmp = 0; + SVCOMPARE_t savecmp = NULL; if (nmemb <= 1) return; /* sorted trivially */ @@ -1409,7 +1410,7 @@ S_qsortsv(pTHX_ gptr *list1, size_t nmemb, SVCOMPARE_t cmp, U32 flags) /* restore prevailing comparison routine */ PL_sort_RealCmp = savecmp; } else if ((flags & SORTf_DESC) != 0) { - SVCOMPARE_t savecmp = PL_sort_RealCmp; /* Save current comparison routine, if any */ + const SVCOMPARE_t savecmp = PL_sort_RealCmp; /* Save current comparison routine, if any */ PL_sort_RealCmp = cmp; /* Put comparison routine where cmp_desc can find it */ cmp = cmp_desc; S_qsortsvu(aTHX_ list1, nmemb, cmp); @@ -1451,10 +1452,10 @@ Sort an array, with various options. void Perl_sortsv_flags(pTHX_ SV **array, size_t nmemb, SVCOMPARE_t cmp, U32 flags) { - void (*sortsvp)(pTHX_ SV **array, size_t nmemb, SVCOMPARE_t cmp, U32 flags) - = ((flags & SORTf_QSORT) != 0 ? S_qsortsv : S_mergesortsv); - - sortsvp(aTHX_ array, nmemb, cmp, flags); + if (flags & SORTf_QSORT) + S_qsortsv(aTHX_ array, nmemb, cmp, flags); + else + S_mergesortsv(aTHX_ array, nmemb, cmp, flags); } #define SvNSIOK(sv) ((SvFLAGS(sv) & SVf_NOK) || ((SvFLAGS(sv) & (SVf_IOK|SVf_IVisUV)) == SVf_IOK)) |