Shallow duplicate in r_vector(const r_vector& rhs)
constructor after all
#387
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.
Reverts part of #383, specifically the note here https://github.com/r-lib/cpp11/pull/383/files#r1723749948
We really do need to call
Rf_shallow_duplicate()
because we want ALL of the attributes on therhs
to get copied over, evendim
anddimnames
.reserve_data()
is meant to be used when we KNOW we have a vector thatpush_back()
has been called on, which should hopefully never be amatrix
(there is nomatrix
API for this). If that holds, then it is ok that thedim
anddimnames
attributes get dropped on growth (i.e. during apush_back()
) and truncation (i.e. in theSEXP
operator).The downside of this comes up when you do:
push_back()
, then use the copy constructor, then return that value. The copy constructor retains all the extra capacity (meaning the allocation is larger than it maybe needs to be), and then when we return the value we also have to truncate. But this combination is probably somewhat rare, so its fine.Without this, literanger breaks. We have now added tests to ensure we can't break this again accidentally.