Factor our hash function used for XRC ids hash map.

Define the hash function in a separate function instead of duplicating it in
XRCID_Lookup() and RemoveXRCIDEntry().

The hash function is extremely simplistic and inefficient right now, it should
be replaced with wxStringHash::stringHash().

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66065 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-11-07 19:34:05 +00:00
parent 74c99b8552
commit d807030e1e

View File

@@ -2409,13 +2409,23 @@ struct XRCID_record
static XRCID_record *XRCID_Records[XRCID_TABLE_SIZE] = {NULL};
static int XRCID_Lookup(const char *str_id, int value_if_not_found = wxID_NONE)
// Extremely simplistic hash function which probably ought to be replaced with
// wxStringHash::stringHash().
static inline unsigned XRCIdHash(const char *str_id)
{
unsigned int index = 0;
unsigned index = 0;
for (const char *c = str_id; *c != '\0'; c++) index += (unsigned int)*c;
index %= XRCID_TABLE_SIZE;
return index;
}
static int XRCID_Lookup(const char *str_id, int value_if_not_found = wxID_NONE)
{
const unsigned index = XRCIdHash(str_id);
XRCID_record *oldrec = NULL;
for (XRCID_record *rec = XRCID_Records[index]; rec; rec = rec->next)
{
@@ -2619,10 +2629,7 @@ wxString wxXmlResource::FindXRCIDById(int numId)
/* static */
void wxIdRangeManager::RemoveXRCIDEntry(const char *str_id)
{
int index = 0;
for (const char *c = str_id; *c != '\0'; c++) index += (int)*c;
index %= XRCID_TABLE_SIZE;
const unsigned index = XRCIdHash(str_id);
XRCID_record **p_previousrec = &XRCID_Records[index];
for (XRCID_record *rec = XRCID_Records[index]; rec; rec = rec->next)