HenrikBengtsson / matrixStats

R package: Methods that Apply to Rows and Columns of Matrices (and to Vectors)
https://cran.r-project.org/package=matrixStats
203 stars 33 forks source link

PERFORMANCE: Make use of constants R_FalseValue and R_TrueValue #131

Closed HenrikBengtsson closed 6 years ago

HenrikBengtsson commented 6 years ago

SEXP constants R_FalseValue and R_TrueValue are defined in src/include/Defn.h. At least (deprecated) matrixStats::anyMissing() allocates a logical vector of length one and then sets it. Using the constants avoids unnecessary allocations and garbage collections. Are there other places where those constants can be used?

UPDATE: They are only accessible via inline ScalarLogical(FALSE), ScalarLogical(TRUE), ... - but those should be equally efficient after compilation.