corrected a bug in ConcatSelf() induced by the latest change
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@743 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -441,43 +441,44 @@ void wxString::ConcatSelf(int nSrcLen, const char *pszSrcData)
|
|||||||
{
|
{
|
||||||
STATISTICS_ADD(SummandLength, nSrcLen);
|
STATISTICS_ADD(SummandLength, nSrcLen);
|
||||||
|
|
||||||
// concatenating an empty string is a NOP, but it happens quite rarely,
|
// concatenating an empty string is a NOP
|
||||||
// so we don't waste our time checking for it
|
if ( nSrcLen > 0 ) {
|
||||||
// if ( nSrcLen > 0 )
|
wxStringData *pData = GetStringData();
|
||||||
wxStringData *pData = GetStringData();
|
size_t nLen = pData->nDataLength;
|
||||||
size_t nLen = pData->nDataLength;
|
size_t nNewLen = nLen + nSrcLen;
|
||||||
size_t nNewLen = nLen + nSrcLen;
|
|
||||||
|
|
||||||
// alloc new buffer if current is too small
|
// alloc new buffer if current is too small
|
||||||
if ( pData->IsShared() ) {
|
if ( pData->IsShared() ) {
|
||||||
STATISTICS_ADD(ConcatHit, 0);
|
STATISTICS_ADD(ConcatHit, 0);
|
||||||
|
|
||||||
// we have to allocate another buffer
|
// we have to allocate another buffer
|
||||||
wxStringData* pOldData = GetStringData();
|
wxStringData* pOldData = GetStringData();
|
||||||
AllocBuffer(nNewLen);
|
AllocBuffer(nNewLen);
|
||||||
memcpy(m_pchData, pOldData->data(), nLen*sizeof(char));
|
memcpy(m_pchData, pOldData->data(), nLen*sizeof(char));
|
||||||
pOldData->Unlock();
|
pOldData->Unlock();
|
||||||
|
}
|
||||||
|
else if ( nNewLen > pData->nAllocLength ) {
|
||||||
|
STATISTICS_ADD(ConcatHit, 0);
|
||||||
|
|
||||||
|
// we have to grow the buffer
|
||||||
|
Alloc(nNewLen);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
STATISTICS_ADD(ConcatHit, 1);
|
||||||
|
|
||||||
|
// the buffer is already big enough
|
||||||
|
}
|
||||||
|
|
||||||
|
// should be enough space
|
||||||
|
wxASSERT( nNewLen <= GetStringData()->nAllocLength );
|
||||||
|
|
||||||
|
// fast concatenation - all is done in our buffer
|
||||||
|
memcpy(m_pchData + nLen, pszSrcData, nSrcLen*sizeof(char));
|
||||||
|
|
||||||
|
m_pchData[nNewLen] = '\0'; // put terminating '\0'
|
||||||
|
GetStringData()->nDataLength = nNewLen; // and fix the length
|
||||||
}
|
}
|
||||||
else if ( nNewLen > pData->nAllocLength ) {
|
//else: the string to append was empty
|
||||||
STATISTICS_ADD(ConcatHit, 0);
|
|
||||||
|
|
||||||
// we have to grow the buffer
|
|
||||||
Alloc(nNewLen);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
STATISTICS_ADD(ConcatHit, 1);
|
|
||||||
|
|
||||||
// the buffer is already big enough
|
|
||||||
}
|
|
||||||
|
|
||||||
// should be enough space
|
|
||||||
wxASSERT( nNewLen <= GetStringData()->nAllocLength );
|
|
||||||
|
|
||||||
// fast concatenation - all is done in our buffer
|
|
||||||
memcpy(m_pchData + nLen, pszSrcData, nSrcLen*sizeof(char));
|
|
||||||
|
|
||||||
m_pchData[nNewLen] = '\0'; // put terminating '\0'
|
|
||||||
GetStringData()->nDataLength = nNewLen; // and fix the length
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Reference in New Issue
Block a user