Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Capture pointer once. Cuts time by about half

  • Loading branch information...
commit 20b9d7b0be7599574d39fad9e91f8765dbc3cca8 1 parent 0a7899d
@hadley authored
Showing with 6 additions and 5 deletions.
  1. +6 −5 src/split-numeric.c
View
11 src/split-numeric.c
@@ -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]++;
Please sign in to comment.
Something went wrong with that request. Please try again.