copyonwrite() on nested LA types will recursively call element copyonwrites even if the top type had count=1

This commit is contained in:
2024-04-03 22:12:08 +02:00
parent 80f915946b
commit 8bbbaa5bae
5 changed files with 43 additions and 8 deletions

View File

@@ -143,7 +143,7 @@ while(l)
}
template <class T>
void SparseMat<T>::copyonwrite(bool detachonly)
void SparseMat<T>::copyonwrite(bool detachonly, bool deep)
{
if(!count)
{
@@ -152,6 +152,18 @@ void SparseMat<T>::copyonwrite(bool detachonly)
return;
}
if(*count == 1 && !LA_traits<T>::is_plaindata() && !detachonly && deep) //type-nested copyonwrite
{
matel<T> *l =list;
while(l)
{
LA_traits<T>::copyonwrite(l->elem);
l=l->next;
}
}
if(*count > 1)
{
(*count)--;