Implemented COW into NzMatrix4; Optimized NzString COW

This commit is contained in:
Lynix
2012-05-07 13:02:07 +02:00
parent 8c420b48c3
commit 45f3fc4e28
7 changed files with 509 additions and 219 deletions

View File

@@ -4177,9 +4177,12 @@ NzString& NzString::operator=(const NzString& string)
ReleaseString();
m_sharedString = string.m_sharedString;
NazaraMutexLock(m_sharedString->mutex);
m_sharedString->refCount++;
NazaraMutexUnlock(m_sharedString->mutex);
if (m_sharedString != &emptyString)
{
NazaraMutexLock(m_sharedString->mutex);
m_sharedString->refCount++;
NazaraMutexUnlock(m_sharedString->mutex);
}
return *this;
}
@@ -5026,6 +5029,9 @@ bool operator>=(const std::string& string, const NzString& nstring)
void NzString::EnsureOwnership()
{
if (m_sharedString == &emptyString)
return;
NazaraLock(m_sharedString->mutex);
if (m_sharedString->refCount > 1)
{
@@ -5051,16 +5057,14 @@ void NzString::ReleaseString()
return;
NazaraMutexLock(m_sharedString->mutex);
if (--m_sharedString->refCount == 0)
m_sharedString->refCount--;
NazaraMutexUnlock(m_sharedString->mutex);
if (m_sharedString->refCount == 0)
{
NazaraMutexUnlock(m_sharedString->mutex);
delete[] m_sharedString->string;
delete m_sharedString;
}
else
{
NazaraMutexUnlock(m_sharedString->mutex);
}
m_sharedString = &emptyString;
}