[Rd] orderVector1 (sort.c): Tiny improvement concerning nalast
EMILIO TORRES MANZANERA
torre@ @end|ng |rom un|ov|@e@
Mon Jan 21 11:22:40 CET 2019
Dear Sir,
In the functions orderVector1, orderVector1l (R-3.5.2/src/main/sort.c) there are two loops concerning nalast (lines 1096, 1105). I am not sure about the possibility of redefining them, so this function should be a little faster.
The first one (line 1096) can be included in the previous 'switch' block (line 1079) (see below). And if you rewrite/duplicate this 'switch' block (line 1079) for the case nalast==false, you should be able to avoid the loop of line 1105.
Best regards,
Emilio
*** /home/emilio/Descargas/R-3.5.2/src/main/sort.c 2018-11-07 00:15:02.000000000 +0100
--- /home/emilio/Descargas/R-3.5.2/src/main/sort2.c 2019-01-21 11:13:07.414332755 +0100
***************
*** 1079,1099 ****
switch (TYPEOF(key)) {
case LGLSXP:
case INTSXP:
! for (i = 0; i < n; i++) isna[i] = (ix[i] == NA_INTEGER);
! break;
case REALSXP:
! for (i = 0; i < n; i++) isna[i] = ISNAN(x[i]);
! break;
case STRSXP:
! for (i = 0; i < n; i++) isna[i] = (sx[i] == NA_STRING);
! break;
case CPLXSXP:
! for (i = 0; i < n; i++) isna[i] = ISNAN(cx[i].r) || ISNAN(cx[i].i);
! break;
default:
! UNIMPLEMENTED_TYPE("orderVector1", key);
}
! for (i = 0; i < n; i++) numna += isna[i];
if(numna)
switch (TYPEOF(key)) {
--- 1079,1111 ----
switch (TYPEOF(key)) {
case LGLSXP:
case INTSXP:
! for (i = 0; i < n; i++) {
! isna[i] = (ix[i] == NA_INTEGER);
! numna += isna[i];
! }
! break;
case REALSXP:
! for (i = 0; i < n; i++){
! isna[i] = ISNAN(x[i]);
! numna += isna[i];
! }
! break;
case STRSXP:
! for (i = 0; i < n; i++){
! isna[i] = (sx[i] == NA_STRING);
! numna += isna[i];
! }
! break;
case CPLXSXP:
! for (i = 0; i < n; i++){
! isna[i] = ISNAN(cx[i].r) || ISNAN(cx[i].i);
! numna += isna[i];
! }
! break;
default:
! UNIMPLEMENTED_TYPE("orderVector1", key);
}
! /* for (i = 0; i < n; i++) numna += isna[i]; */
if(numna)
switch (TYPEOF(key)) {
--
=================================================
Emilio Torres Manzanera
Fac. de Comercio - Universidad de Oviedo
c/ Luis Moya 261, E-33203 Gijón (Spain)
Tel. 985 182 197 email: torres using uniovi.es
=================================================
More information about the R-devel
mailing list