Permalink
Browse files

Slightly more idiomatic C code

  • Loading branch information...
1 parent 8453287 commit 0a7899d34cb4e4314aa02c29cd7885df7a7fa38b @hadley committed Oct 12, 2012
Showing with 2 additions and 5 deletions.
  1. +2 −5 src/split-numeric.c
View
@@ -5,12 +5,9 @@ SEXP split_indices(SEXP group, SEXP n) {
SEXP vec;
int i, j, k, nobs, nlevs;
- PROTECT(group = AS_INTEGER(group));
-
nlevs = INTEGER(n)[0];
nobs = LENGTH(group);
-
// Count number of cases in each group
int counts[nlevs];
for (i = 0; i < nlevs; i++)
@@ -34,8 +31,8 @@ SEXP split_indices(SEXP group, SEXP n) {
j = INTEGER(group)[i] - 1;
k = counts[j];
INTEGER(VECTOR_ELT(vec, j))[k] = i + 1;
- counts[j] += 1;
+ counts[j]++;
}
- UNPROTECT(2);
+ UNPROTECT(1);
return vec;
}

0 comments on commit 0a7899d

Please sign in to comment.