From marius.hofert at uwaterloo.ca  Fri Oct  9 13:53:41 2015
From: marius.hofert at uwaterloo.ca (Marius Hofert)
Date: Fri, 9 Oct 2015 13:53:41 +0200
Subject: [Rd] Improvement of R_orderVector() via orderVector1()
Message-ID: <CAM3-KjZo6fDqMm2GRYfZT_eU=Aiuo0tPuZEH6aJ=g_Btux552Q@mail.gmail.com>

Hi,

I think R_orderVector() can be improved by calling orderVector1() if
possible. In a problem we had, this gave us a run time improvement
factor of 4.... so my hope is that this can be included. Below is the
suggested change, I'm just not 100% sure if the test "CDR(arglist) ==
R_NilValue" is good...

Cheers,
Marius

void R_orderVector(int *indx, // must be pre-allocated to length >= n
                   int n,
                   SEXP arglist, // <- e.g.  Rf_lang2(x,y)
                   Rboolean nalast, Rboolean decreasing)
{
    // idx[] <- 0:(n-1) :
    for(int i = 0; i < n; i++) indx[i] = i;
    if(CDR(arglist) == R_NilValue) {
        orderVector1(indx, n, CAR(arglist), nalast, decreasing, R_NilValue);
    } else {
        orderVector(indx, n, arglist, nalast, decreasing, listgreater);
    }
    return;
}



[Rd] Improvement of R_orderVector() via orderVector1()
Marius Hofert