Permalink
Browse files

Capture pointer once. Cuts time by about half

  • Loading branch information...
1 parent 0a7899d commit 20b9d7b0be7599574d39fad9e91f8765dbc3cca8 @hadley committed Oct 12, 2012
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/split-numeric.c
View
@@ -3,17 +3,18 @@
SEXP split_indices(SEXP group, SEXP n) {
SEXP vec;
- int i, j, k, nobs, nlevs;
+ int i, j, k;
- nlevs = INTEGER(n)[0];
- nobs = LENGTH(group);
+ int nlevs = INTEGER(n)[0];
+ int nobs = LENGTH(group);
+ int *pgroup = INTEGER(group);
// Count number of cases in each group
int counts[nlevs];
for (i = 0; i < nlevs; i++)
counts[i] = 0;
for (i = 0; i < nobs; i++) {
- j = INTEGER(group)[i] - 1;
+ j = pgroup[i] - 1;
counts[j]++;
}
@@ -28,7 +29,7 @@ SEXP split_indices(SEXP group, SEXP n) {
counts[i] = 0;
}
for (i = 0; i < nobs; i++) {
- j = INTEGER(group)[i] - 1;
+ j = pgroup[i] - 1;
k = counts[j];
INTEGER(VECTOR_ELT(vec, j))[k] = i + 1;
counts[j]++;

0 comments on commit 20b9d7b

Please sign in to comment.