Re: [Rd] Proposed speedup of ifelse

2018-05-02 Thread Hugh Parsonage
And the patch itself: --- a/src/library/base/R/ifelse.R +++ b/src/library/base/R/ifelse.R @@ -18,12 +18,14 @@ ifelse <- function (test, yes, no) { + attributes_of_test <- attributes(test) + if(is.atomic(test)) { # do not lose attributes if (typeof(test) != "logical") storage.mo

[Rd] Proposed speedup of ifelse

2018-05-02 Thread Hugh Parsonage
I propose a patch to ifelse that leverages anyNA(test) to achieve an improvement in performance. For a test vector of length 10, the change nearly halves the time taken and for a test of length 1 million, there is a tenfold increase in speed. Even for small vectors, the distributions of timings bet