blead 25801: Symbian batch of today
[p5sagit/p5-mst-13.2.git] / pp_sort.c
index 59f975e..3dda7cc 100644 (file)
--- a/pp_sort.c
+++ b/pp_sort.c
@@ -269,7 +269,7 @@ dynprep(pTHX_ gptr *list1, gptr *list2, size_t nmemb, SVCOMPARE_t cmp)
  * problem is subdivided into smaller and smaller parts, the parts
  * fit into smaller (and faster) caches.  So it doesn't matter how
  * many levels of cache exist, quicksort will "find" them, and,
- * as long as smaller is faster, take advanatge of them.
+ * as long as smaller is faster, take advantage of them.
  *
  * By contrast, consider how the original mergesort algorithm worked.
  * Suppose we have five runs (each typically of length 2 after dynprep).
@@ -355,11 +355,11 @@ cmp_desc(pTHX_ gptr a, gptr b)
 STATIC void
 S_mergesortsv(pTHX_ gptr *base, size_t nmemb, SVCOMPARE_t cmp, U32 flags)
 {
-    IV i, run, runs, offset;
+    IV i, run, offset;
     I32 sense, level;
+    register gptr *f1, *f2, *t, *b, *p;
     int iwhich;
-    register gptr *f1, *f2, *t, *b, *p, *tp2, *l1, *l2, *q;
-    gptr *aux, *list1, *list2;
+    gptr *aux;
     gptr *p1;
     gptr small[SMALLSORT];
     gptr *which[3];
@@ -375,7 +375,7 @@ S_mergesortsv(pTHX_ gptr *base, size_t nmemb, SVCOMPARE_t cmp, U32 flags)
     }
 
     if (nmemb <= SMALLSORT) aux = small;       /* use stack for aux array */
-    else { New(799,aux,nmemb,gptr); }          /* allocate auxilliary array */
+    else { Newx(aux,nmemb,gptr); }             /* allocate auxilliary array */
     level = 0;
     stackp = stack;
     stackp->runs = dynprep(aTHX_ base, aux, nmemb, cmp);
@@ -388,11 +388,14 @@ S_mergesortsv(pTHX_ gptr *base, size_t nmemb, SVCOMPARE_t cmp, U32 flags)
         * is needed at the next level up.  Hop up a level, and,
         * as long as stackp->runs is 0, keep merging.
         */
-       if ((runs = stackp->runs) == 0) {
+       IV runs = stackp->runs;
+       if (runs == 0) {
+           gptr *list1, *list2;
            iwhich = level & 1;
            list1 = which[iwhich];              /* area where runs are now */
            list2 = which[++iwhich];            /* area for merged runs */
            do {
+               register gptr *l1, *l2, *tp2;
                offset = stackp->offset;
                f1 = p1 = list1 + offset;               /* start of first run */
                p = tp2 = list2 + offset;       /* where merged run will go */
@@ -422,7 +425,7 @@ S_mergesortsv(pTHX_ gptr *base, size_t nmemb, SVCOMPARE_t cmp, U32 flags)
                    ** and -1 when equality should look high.
                    */
 
-
+                   register gptr *q;
                    if (cmp(aTHX_ *f1, *f2) <= 0) {
                        q = f2; b = f1; t = l1;
                        sense = -1;
@@ -1358,7 +1361,7 @@ S_qsortsv(pTHX_ gptr *list1, size_t nmemb, SVCOMPARE_t cmp, U32 flags)
 
         /* Small arrays can use the stack, big ones must be allocated */
         if (nmemb <= SMALLSORT) indir = small;
-        else { New(1799, indir, nmemb, gptr *); }
+        else { Newx(indir, nmemb, gptr *); }
 
         /* Copy pointers to original array elements into indirect array */
         for (n = nmemb, pp = indir, q = list1; n--; ) *pp++ = q++;
@@ -1544,7 +1547,8 @@ PP(pp_sort)
                SAVEVPTR(CvROOT(cv)->op_ppaddr);
                CvROOT(cv)->op_ppaddr = PL_ppaddr[OP_NULL];
 
-               PAD_SET_CUR(CvPADLIST(cv), 1);
+               SAVECOMPPAD();
+               PAD_SET_CUR_NOSAVE(CvPADLIST(cv), 1);
             }
        }
     }
@@ -1712,7 +1716,7 @@ PP(pp_sort)
        av_extend(av, max);
        for (i=0; i < max; i++) {
            SV * const sv = base[i];
-           SV **didstore = av_store(av, i, sv);
+           SV ** const didstore = av_store(av, i, sv);
            if (SvSMAGICAL(sv))
                mg_set(sv);
            if (!didstore)