corrected bug in wxArrayString::operator= and it's copy ctor
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@317 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1073,33 +1073,24 @@ wxArrayString::wxArrayString()
|
|||||||
// copy ctor
|
// copy ctor
|
||||||
wxArrayString::wxArrayString(const wxArrayString& src)
|
wxArrayString::wxArrayString(const wxArrayString& src)
|
||||||
{
|
{
|
||||||
m_nSize = src.m_nSize;
|
m_pItems = NULL;
|
||||||
m_nCount = src.m_nCount;
|
|
||||||
|
|
||||||
if ( m_nSize != 0 )
|
*this = src;
|
||||||
m_pItems = new char *[m_nSize];
|
|
||||||
else
|
|
||||||
m_pItems = NULL;
|
|
||||||
|
|
||||||
if ( m_nCount != 0 )
|
|
||||||
memcpy(m_pItems, src.m_pItems, m_nCount*sizeof(char *));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy operator
|
// assignment operator
|
||||||
wxArrayString& wxArrayString::operator=(const wxArrayString& src)
|
wxArrayString& wxArrayString::operator=(const wxArrayString& src)
|
||||||
{
|
{
|
||||||
DELETEA(m_pItems);
|
DELETEA(m_pItems);
|
||||||
|
|
||||||
m_nSize = src.m_nSize;
|
m_nSize = 0;
|
||||||
m_nCount = src.m_nCount;
|
if ( src.m_nCount > ARRAY_DEFAULT_INITIAL_SIZE )
|
||||||
|
Alloc(src.m_nCount);
|
||||||
|
|
||||||
if ( m_nSize != 0 )
|
// we can't just copy the pointers here because otherwise we would share
|
||||||
m_pItems = new char *[m_nCount];
|
// the strings with another array
|
||||||
else
|
for ( uint n = 0; n < src.m_nCount; n++ )
|
||||||
m_pItems = NULL;
|
Add(src[n]);
|
||||||
|
|
||||||
if ( m_nCount != 0 )
|
|
||||||
memcpy(m_pItems, src.m_pItems, m_nCount*sizeof(char *));
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -1116,7 +1107,8 @@ void wxArrayString::Grow()
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// add 50% but not too much
|
// add 50% but not too much
|
||||||
size_t nIncrement = m_nSize >> 1;
|
size_t nIncrement = m_nSize < ARRAY_DEFAULT_INITIAL_SIZE
|
||||||
|
? ARRAY_DEFAULT_INITIAL_SIZE : m_nSize >> 1;
|
||||||
if ( nIncrement > ARRAY_MAXSIZE_INCREMENT )
|
if ( nIncrement > ARRAY_MAXSIZE_INCREMENT )
|
||||||
nIncrement = ARRAY_MAXSIZE_INCREMENT;
|
nIncrement = ARRAY_MAXSIZE_INCREMENT;
|
||||||
m_nSize += nIncrement;
|
m_nSize += nIncrement;
|
||||||
|
Reference in New Issue
Block a user