fixed DeleteContents inconsistency: didn't free memory if DeleteContents called before inserting data (and creating wxList)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5812 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -104,7 +104,7 @@ class WXDLLEXPORT wxHashTable: public wxObject
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_count; // number of elements in the hashtable
|
size_t m_count; // number of elements in the hashtable
|
||||||
|
bool m_deleteContents;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -37,6 +37,7 @@ wxHashTable::wxHashTable (int the_key_type, int size)
|
|||||||
hash_table = (wxList**) NULL;
|
hash_table = (wxList**) NULL;
|
||||||
Create(the_key_type, size);
|
Create(the_key_type, size);
|
||||||
m_count = 0;
|
m_count = 0;
|
||||||
|
m_deleteContents = FALSE;
|
||||||
/*
|
/*
|
||||||
n = size;
|
n = size;
|
||||||
current_position = -1;
|
current_position = -1;
|
||||||
@@ -110,7 +111,10 @@ void wxHashTable::Put (long key, long value, wxObject * object)
|
|||||||
|
|
||||||
int position = (int) (k % n);
|
int position = (int) (k % n);
|
||||||
if (!hash_table[position])
|
if (!hash_table[position])
|
||||||
|
{
|
||||||
hash_table[position] = new wxList (wxKEY_INTEGER);
|
hash_table[position] = new wxList (wxKEY_INTEGER);
|
||||||
|
if (m_deleteContents) hash_table[position]->DeleteContents(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
hash_table[position]->Append (value, object);
|
hash_table[position]->Append (value, object);
|
||||||
m_count++;
|
m_count++;
|
||||||
@@ -125,7 +129,10 @@ void wxHashTable::Put (long key, const wxChar *value, wxObject * object)
|
|||||||
|
|
||||||
int position = (int) (k % n);
|
int position = (int) (k % n);
|
||||||
if (!hash_table[position])
|
if (!hash_table[position])
|
||||||
|
{
|
||||||
hash_table[position] = new wxList (wxKEY_INTEGER);
|
hash_table[position] = new wxList (wxKEY_INTEGER);
|
||||||
|
if (m_deleteContents) hash_table[position]->DeleteContents(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
hash_table[position]->Append (value, object);
|
hash_table[position]->Append (value, object);
|
||||||
m_count++;
|
m_count++;
|
||||||
@@ -140,7 +147,10 @@ void wxHashTable::Put (long key, wxObject * object)
|
|||||||
|
|
||||||
int position = (int) (k % n);
|
int position = (int) (k % n);
|
||||||
if (!hash_table[position])
|
if (!hash_table[position])
|
||||||
|
{
|
||||||
hash_table[position] = new wxList (wxKEY_INTEGER);
|
hash_table[position] = new wxList (wxKEY_INTEGER);
|
||||||
|
if (m_deleteContents) hash_table[position]->DeleteContents(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
hash_table[position]->Append (k, object);
|
hash_table[position]->Append (k, object);
|
||||||
m_count++;
|
m_count++;
|
||||||
@@ -151,7 +161,10 @@ void wxHashTable::Put (const wxChar *key, wxObject * object)
|
|||||||
int position = (int) (MakeKey (key) % n);
|
int position = (int) (MakeKey (key) % n);
|
||||||
|
|
||||||
if (!hash_table[position])
|
if (!hash_table[position])
|
||||||
|
{
|
||||||
hash_table[position] = new wxList (wxKEY_STRING);
|
hash_table[position] = new wxList (wxKEY_STRING);
|
||||||
|
if (m_deleteContents) hash_table[position]->DeleteContents(TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
hash_table[position]->Append (key, object);
|
hash_table[position]->Append (key, object);
|
||||||
m_count++;
|
m_count++;
|
||||||
@@ -369,6 +382,7 @@ wxNode *wxHashTable::Next (void)
|
|||||||
void wxHashTable::DeleteContents (bool flag)
|
void wxHashTable::DeleteContents (bool flag)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
m_deleteContents = flag;
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
if (hash_table[i])
|
if (hash_table[i])
|
||||||
|
Reference in New Issue
Block a user