Skip to content

Commit e243ece

Browse files
committed
Use growable_allocate() in subsetDT()
1 parent f927451 commit e243ece

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/subset.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,16 +297,14 @@ SEXP subsetDT(SEXP x, SEXP rows, SEXP cols) { // API change needs update NEWS.md
297297
}
298298

299299
int overAlloc = checkOverAlloc(GetOption(install("datatable.alloccol"), R_NilValue));
300-
SEXP ans = PROTECT(allocVector(VECSXP, LENGTH(cols)+overAlloc)); nprotect++; // doing alloc.col directly here; eventually alloc.col can be deprecated.
300+
SEXP ans = PROTECT(growable_allocate(VECSXP, LENGTH(cols), LENGTH(cols)+overAlloc)); nprotect++; // doing alloc.col directly here; eventually alloc.col can be deprecated.
301301

302302
// user-defined and superclass attributes get copied as from v1.12.0
303303
copyMostAttrib(x, ans);
304304
// most means all except R_NamesSymbol, R_DimSymbol and R_DimNamesSymbol
305305
// includes row.names (oddly, given other dims aren't) and "sorted" dealt with below
306306
// class is also copied here which retains superclass name in class vector as has been the case for many years; e.g. tests 1228.* for #64
307307

308-
SET_TRUELENGTH(ans, LENGTH(ans));
309-
SETLENGTH(ans, LENGTH(cols));
310308
int ansn;
311309
if (isNull(rows)) {
312310
ansn = nrow;
@@ -329,9 +327,7 @@ SEXP subsetDT(SEXP x, SEXP rows, SEXP cols) { // API change needs update NEWS.md
329327
subsetVectorRaw(target, source, rows, anyNA); // parallel within column
330328
}
331329
}
332-
SEXP tmp = PROTECT(allocVector(STRSXP, LENGTH(cols)+overAlloc)); nprotect++;
333-
SET_TRUELENGTH(tmp, LENGTH(tmp));
334-
SETLENGTH(tmp, LENGTH(cols));
330+
SEXP tmp = PROTECT(growable_allocate(STRSXP, LENGTH(cols), LENGTH(cols)+overAlloc)); nprotect++;
335331
setAttrib(ans, R_NamesSymbol, tmp);
336332
subsetVectorRaw(tmp, getAttrib(x, R_NamesSymbol), cols, /*anyNA=*/false);
337333

0 commit comments

Comments
 (0)