-
Notifications
You must be signed in to change notification settings - Fork 1k
copy(): only overwrite the list when necessary, consider the attributes
#7820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
aitap
wants to merge
5
commits into
master
Choose a base branch
from
fix7456
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21831,3 +21831,9 @@ test(2378.92, .Call(CresizeVector, x, 2:3), error = "must be length 1 non-NA non | |
| test(2378.93, .Call(CresizeVector, x, -2L), error = "must be length 1 non-NA non-negative integer value") | ||
| test(2378.94, .Call(CresizeVector, x, NA_integer_), error = "must be length 1 non-NA non-negative integer value") | ||
| test(2378.95, .Call(CresizeVector, NULL, 2L), error = "must be a vector") | ||
|
|
||
| # copy() reallocates data.tables inside list attributes, #7820 | ||
| x = list() | ||
| attr(x, 'dt') = data.table() | ||
| test(2379, truelength(attr(copy(x), 'dt')) > 0L) | ||
| rm(x) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add a test for nested tables? |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -57,9 +57,48 @@ SEXP setlevels(SEXP x, SEXP levels, SEXP ulevels) { | |||||
| return(x); | ||||||
| } | ||||||
|
|
||||||
| SEXP copy(SEXP x) | ||||||
| { | ||||||
| return(duplicate(x)); | ||||||
| struct realloc_nested_dt_attr_ctx { | ||||||
| SEXP x; | ||||||
| int overAlloc; | ||||||
| }; | ||||||
| static SEXP realloc_nested_dt_list(SEXP x, int overAlloc, bool); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or dont name arguments at all. |
||||||
| static SEXP realloc_nested_dt_list_attr(SEXP tag, SEXP att, void *ctx_) { | ||||||
| struct realloc_nested_dt_attr_ctx *ctx = ctx_; | ||||||
| SEXP newatt = realloc_nested_dt_list(att, ctx->overAlloc, false); | ||||||
| if (newatt != att) { | ||||||
| PROTECT(newatt); | ||||||
| setAttrib(ctx->x, tag, newatt); | ||||||
| UNPROTECT(1); | ||||||
| } | ||||||
| return R_NilValue; | ||||||
| } | ||||||
| static SEXP realloc_nested_dt_list(SEXP x, int overAlloc, bool replacePairlists) { | ||||||
| int nprot = 0; | ||||||
| if (inherits(x, "data.table")) { | ||||||
| x = PROTECT(alloccol(x, LENGTH(x) + overAlloc, FALSE)); ++nprot; | ||||||
| unlock(x); | ||||||
| } | ||||||
| if (replacePairlists && TYPEOF(x) == LISTSXP) { | ||||||
| x = PROTECT(coerceVector(x, VECSXP)); ++nprot; | ||||||
| } | ||||||
| if (TYPEOF(x) == VECSXP) for (R_xlen_t i = 0; i < XLENGTH(x); ++i) { | ||||||
| SEXP xi = VECTOR_ELT(x, i); | ||||||
| SEXP xinew = realloc_nested_dt_list(xi, overAlloc, false); | ||||||
| if (xinew != xi) | ||||||
| SET_VECTOR_ELT(x, i, xinew); | ||||||
| } | ||||||
| struct realloc_nested_dt_attr_ctx ctx = { .x = x, .overAlloc = overAlloc }; | ||||||
| R_mapAttrib(x, realloc_nested_dt_list_attr, &ctx); | ||||||
| UNPROTECT(nprot); | ||||||
| return x; | ||||||
| } | ||||||
|
|
||||||
| SEXP copy(SEXP x, SEXP overAllocArg) { | ||||||
| int overAlloc = checkOverAlloc(overAllocArg); | ||||||
| PROTECT(x = duplicate(x)); | ||||||
| x = realloc_nested_dt_list(x, overAlloc, true); | ||||||
| UNPROTECT(1); | ||||||
| return x; | ||||||
| } | ||||||
|
|
||||||
| // Internal use only. So that := can update elements of a list of data.table, #2204. Just needed to overallocate/grow the VECSXP. | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if we have multiple attributes like: