Skip to content

Commit 92b8444

Browse files
author
luke
committed
Simplifications and cleanups for resizable vectors.
git-svn-id: https://svn.r-project.org/R/trunk@89045 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 8a0853d commit 92b8444

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/include/Rinternals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ void R_clrhash(R_hashtab_type h);
12361236
bool R_isResizable(SEXP x);
12371237
R_xlen_t R_maxLength(SEXP x);
12381238
void R_resizeVector(SEXP x, R_xlen_t newlen);
1239-
SEXP R_allocResizableVector(SEXPTYPE type, R_xlen_t len, R_xlen_t maxlen);
1239+
SEXP R_allocResizableVector(SEXPTYPE type, R_xlen_t maxlen);
12401240
SEXP R_duplicateAsResizable(SEXP x);
12411241

12421242

src/main/memory.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5020,7 +5020,7 @@ R_xlen_t R_maxLength(SEXP x)
50205020
return GROWABLE_BIT_SET(x) ? XTRUELENGTH(x) : xlength(x);
50215021
}
50225022

5023-
SEXP R_allocResizableVector(SEXPTYPE type, R_xlen_t len, R_xlen_t maxlen)
5023+
SEXP R_allocResizableVector(SEXPTYPE type, R_xlen_t maxlen)
50245024
{
50255025
switch (type) {
50265026
case LGLSXP:
@@ -5036,12 +5036,9 @@ SEXP R_allocResizableVector(SEXPTYPE type, R_xlen_t len, R_xlen_t maxlen)
50365036
error(_("cannot make a resizable vector of type '%s'"),
50375037
sexptype2char(type));
50385038
}
5039-
if (len > maxlen)
5040-
error(_("len larger than maxlen"));
50415039
SEXP val = allocVector(type, maxlen);
50425040
SET_TRUELENGTH(val, maxlen);
50435041
SET_GROWABLE_BIT(val);
5044-
SETLENGTH(val, len);
50455042
return val;
50465043
}
50475044

@@ -5081,19 +5078,14 @@ void R_resizeVector(SEXP x, R_xlen_t newlen)
50815078
error(_("not a resizable vector"));
50825079
if (newlen > XTRUELENGTH(x))
50835080
error(_("'newlen' is too large"));
5084-
if (MAYBE_SHARED(x))
5085-
error(_("can't resize a vector that might be shared"));
50865081
if (ATTRIB(x) != R_NilValue) {
5082+
// clear length-dependent attributes
50875083
if (getAttrib(x, R_DimSymbol) != R_NilValue)
5088-
error(_("can't resize a vector with a 'dim' attribute"));
5084+
setAttrib(x, R_DimSymbol, R_NilValue);
50895085
if (getAttrib(x, R_DimNamesSymbol) != R_NilValue)
5090-
error(_("can't resize a vector with a 'dimnames' attribute"));
5091-
SEXP names = getAttrib(x, R_NamesSymbol);
5092-
if (names != R_NilValue) {
5093-
if (MAYBE_SHARED(names))
5094-
error(_("can't resize 'names' that might be shared"));
5095-
R_resizeVector(names, newlen);
5096-
}
5086+
setAttrib(x, R_DimNamesSymbol, R_NilValue);
5087+
if (getAttrib(x, R_NamesSymbol) != R_NilValue)
5088+
setAttrib(x, R_NamesSymbol, R_NilValue);
50975089
}
50985090
R_xlen_t len = XLENGTH(x);
50995091
if (newlen < len) // clear dropped elements to drop refcounts

0 commit comments

Comments
 (0)