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 <
[email protected] >
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
+
1
7
2016-01-29 Dirk Eddelbuettel <
[email protected] >
2
8
3
9
* 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 {
144
144
#endif
145
145
146
146
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;
150
154
}
151
155
152
156
void get_indices ( traits::identity< traits::int2type<REALSXP> > t ) {
@@ -215,13 +219,7 @@ class SubsetProxy {
215
219
int lhs_n;
216
220
int rhs_n;
217
221
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;
225
223
226
224
// because of the above, we keep track of the size
227
225
int indices_n;
Original file line number Diff line number Diff line change @@ -823,3 +823,8 @@ String vec_print_integer(IntegerVector v) {
823
823
buf << v;
824
824
return buf.str ();
825
825
}
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) {
720
720
s <- vec_print_character(v )
721
721
checkEquals(s , ' "a" "b" "c" "d"' )
722
722
}
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
+ }
723
732
}
724
733
You can’t perform that action at this time.
0 commit comments