File tree Expand file tree Collapse file tree 4 files changed +28
-10
lines changed
Expand file tree Collapse file tree 4 files changed +28
-10
lines changed Original file line number Diff line number Diff line change 1+ 2016-01-30 Qiang Kou <qkou@umail.iu.edu>
2+
3+ * inst//include/Rcpp/vector/Subsetter.h: fix the error under gc
4+ * inst/unitTests/cpp/Vector.cpp : Add tests
5+ * inst/unitTests/runit.Vector.R : Idem
6+
172016-01-29 Dirk Eddelbuettel <edd@debian.org>
28
39 * vignettes/Rcpp-FAQ.Rnw (Rcpp): Add new entry about required TeXlive
Original file line number Diff line number Diff line change @@ -144,9 +144,13 @@ class SubsetProxy {
144144 #endif
145145
146146 void get_indices ( traits::identity< traits::int2type<INTSXP> > t ) {
147- indices = INTEGER (rhs);
148- indices_n = rhs_n;
149- check_indices (indices, rhs_n, lhs_n);
147+ indices.reserve (rhs_n);
148+ int * ptr = INTEGER (rhs);
149+ check_indices (ptr, rhs_n, lhs_n);
150+ for (int i=0 ; i < rhs_n; ++i) {
151+ indices.push_back ( rhs[i] );
152+ }
153+ indices_n = rhs_n;
150154 }
151155
152156 void get_indices ( traits::identity< traits::int2type<REALSXP> > t ) {
@@ -215,13 +219,7 @@ class SubsetProxy {
215219 int lhs_n;
216220 int rhs_n;
217221
218- // we want to reuse the indices if an IntegerVector is passed in; otherwise,
219- // we construct a std::vector<int> to hold the indices
220- typename traits::if_<
221- RHS_RTYPE == INTSXP,
222- int *,
223- std::vector<int >
224- >::type indices;
222+ std::vector<int > indices;
225223
226224 // because of the above, we keep track of the size
227225 int indices_n;
Original file line number Diff line number Diff line change @@ -823,3 +823,8 @@ String vec_print_integer(IntegerVector v) {
823823 buf << v;
824824 return buf.str ();
825825}
826+
827+ // [[Rcpp::export]]
828+ IntegerVector vec_subset (IntegerVector x, IntegerVector y) {
829+ return x[y - 1 ];
830+ }
Original file line number Diff line number Diff line change @@ -720,5 +720,14 @@ if (.runThisTest) {
720720 s <- vec_print_character(v )
721721 checkEquals(s , ' "a" "b" "c" "d"' )
722722 }
723+
724+ test.IntegerVector.subset.under.gc <- function () {
725+ x <- 1 : 1E6
726+ y <- 1 : 1E6
727+ gctorture(TRUE )
728+ z <- vec_subset(x , y )
729+ gctorture(FALSE )
730+ checkEquals(x [y ], z )
731+ }
723732}
724733
You can’t perform that action at this time.
0 commit comments