Permalink
Browse files

Revert C code changes from 03e1af8 because they don't fix the problem

  • Loading branch information...
1 parent ed4ccd8 commit e791f4d6faca402e5e915877b565e10f670427cf @wch wch committed Nov 29, 2012
Showing with 8 additions and 11 deletions.
  1. +8 −11 src/split-numeric.c
View
@@ -10,34 +10,31 @@ SEXP split_indices(SEXP group, SEXP n) {
int *pgroup = INTEGER(group);
// Count number of cases in each group
- SEXP counts;
- PROTECT(counts = allocVector(INTSXP, nlevs));
- int *pcounts = INTEGER(counts);
-
+ int counts[nlevs];
for (i = 0; i < nlevs; i++)
- pcounts[i] = 0;
+ counts[i] = 0;
for (i = 0; i < nobs; i++) {
j = pgroup[i];
if (j > nlevs) error("n smaller than largest index");
- pcounts[j - 1]++;
+ counts[j - 1]++;
}
// Allocate storage for results
PROTECT(vec = allocVector(VECSXP, nlevs));
for (i = 0; i < nlevs; i++) {
- SET_VECTOR_ELT(vec, i, allocVector(INTSXP, pcounts[i]));
+ SET_VECTOR_ELT(vec, i, allocVector(INTSXP, counts[i]));
}
// Put indices in groups
for (i = 0; i < nlevs; i++) {
- pcounts[i] = 0;
+ counts[i] = 0;
}
for (i = 0; i < nobs; i++) {
j = pgroup[i] - 1;
- k = pcounts[j];
+ k = counts[j];
INTEGER(VECTOR_ELT(vec, j))[k] = i + 1;
- pcounts[j]++;
+ counts[j]++;
}
- UNPROTECT(2);
+ UNPROTECT(1);
return vec;
}

0 comments on commit e791f4d

Please sign in to comment.