msi: Improve the string table hash.
This commit is contained in:
parent
f5d3adaf59
commit
f537eb241a
|
@ -37,9 +37,11 @@
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
WINE_DEFAULT_DEBUG_CHANNEL(msidb);
|
||||||
|
|
||||||
|
#define HASH_SIZE 67
|
||||||
|
|
||||||
typedef struct _msistring
|
typedef struct _msistring
|
||||||
{
|
{
|
||||||
UINT hash;
|
int hash_next;
|
||||||
UINT refcount;
|
UINT refcount;
|
||||||
LPWSTR str;
|
LPWSTR str;
|
||||||
} msistring;
|
} msistring;
|
||||||
|
@ -49,6 +51,7 @@ struct string_table
|
||||||
UINT maxcount; /* the number of strings */
|
UINT maxcount; /* the number of strings */
|
||||||
UINT freeslot;
|
UINT freeslot;
|
||||||
UINT codepage;
|
UINT codepage;
|
||||||
|
int hash[HASH_SIZE];
|
||||||
msistring *strings; /* an array of strings (in the tree) */
|
msistring *strings; /* an array of strings (in the tree) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,12 +68,13 @@ static UINT msistring_makehash( const WCHAR *str )
|
||||||
hash *= 53;
|
hash *= 53;
|
||||||
hash = (hash<<5) | (hash>>27);
|
hash = (hash<<5) | (hash>>27);
|
||||||
}
|
}
|
||||||
return hash;
|
return hash % HASH_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
string_table *msi_init_stringtable( int entries, UINT codepage )
|
string_table *msi_init_stringtable( int entries, UINT codepage )
|
||||||
{
|
{
|
||||||
string_table *st;
|
string_table *st;
|
||||||
|
int i;
|
||||||
|
|
||||||
st = msi_alloc( sizeof (string_table) );
|
st = msi_alloc( sizeof (string_table) );
|
||||||
if( !st )
|
if( !st )
|
||||||
|
@ -87,6 +91,9 @@ string_table *msi_init_stringtable( int entries, UINT codepage )
|
||||||
st->freeslot = 1;
|
st->freeslot = 1;
|
||||||
st->codepage = codepage;
|
st->codepage = codepage;
|
||||||
|
|
||||||
|
for( i=0; i<HASH_SIZE; i++ )
|
||||||
|
st->hash[i] = -1;
|
||||||
|
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,15 +140,23 @@ static int st_find_free_entry( string_table *st )
|
||||||
return st->freeslot;
|
return st->freeslot;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void st_mark_entry_used( string_table *st, UINT n )
|
static void set_st_entry( string_table *st, UINT n, LPWSTR str )
|
||||||
{
|
{
|
||||||
if( n >= st->maxcount )
|
UINT hash = msistring_makehash( str );
|
||||||
return;
|
|
||||||
st->freeslot = n + 1;
|
st->strings[n].refcount = 1;
|
||||||
|
st->strings[n].str = str;
|
||||||
|
|
||||||
|
st->strings[n].hash_next = st->hash[hash];
|
||||||
|
st->hash[hash] = n;
|
||||||
|
|
||||||
|
if( n < st->maxcount )
|
||||||
|
st->freeslot = n + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msi_addstring( string_table *st, UINT n, const CHAR *data, int len, UINT refcount )
|
int msi_addstring( string_table *st, UINT n, const CHAR *data, int len, UINT refcount )
|
||||||
{
|
{
|
||||||
|
LPWSTR str;
|
||||||
int sz;
|
int sz;
|
||||||
|
|
||||||
if( !data )
|
if( !data )
|
||||||
|
@ -175,21 +190,21 @@ int msi_addstring( string_table *st, UINT n, const CHAR *data, int len, UINT ref
|
||||||
if( len < 0 )
|
if( len < 0 )
|
||||||
len = strlen(data);
|
len = strlen(data);
|
||||||
sz = MultiByteToWideChar( st->codepage, 0, data, len, NULL, 0 );
|
sz = MultiByteToWideChar( st->codepage, 0, data, len, NULL, 0 );
|
||||||
st->strings[n].str = msi_alloc( (sz+1)*sizeof(WCHAR) );
|
str = msi_alloc( (sz+1)*sizeof(WCHAR) );
|
||||||
if( !st->strings[n].str )
|
if( !str )
|
||||||
return -1;
|
return -1;
|
||||||
MultiByteToWideChar( st->codepage, 0, data, len, st->strings[n].str, sz );
|
MultiByteToWideChar( st->codepage, 0, data, len, str, sz );
|
||||||
st->strings[n].str[sz] = 0;
|
str[sz] = 0;
|
||||||
st->strings[n].refcount = 1;
|
|
||||||
st->strings[n].hash = msistring_makehash( st->strings[n].str );
|
|
||||||
|
|
||||||
st_mark_entry_used( st, n );
|
set_st_entry( st, n, str );
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
int msi_addstringW( string_table *st, UINT n, const WCHAR *data, int len, UINT refcount )
|
int msi_addstringW( string_table *st, UINT n, const WCHAR *data, int len, UINT refcount )
|
||||||
{
|
{
|
||||||
|
LPWSTR str;
|
||||||
|
|
||||||
/* TRACE("[%2d] = %s\n", string_no, debugstr_an(data,len) ); */
|
/* TRACE("[%2d] = %s\n", string_no, debugstr_an(data,len) ); */
|
||||||
|
|
||||||
if( !data )
|
if( !data )
|
||||||
|
@ -224,16 +239,14 @@ int msi_addstringW( string_table *st, UINT n, const WCHAR *data, int len, UINT r
|
||||||
len = strlenW(data);
|
len = strlenW(data);
|
||||||
TRACE("%s, n = %d len = %d\n", debugstr_w(data), n, len );
|
TRACE("%s, n = %d len = %d\n", debugstr_w(data), n, len );
|
||||||
|
|
||||||
st->strings[n].str = msi_alloc( (len+1)*sizeof(WCHAR) );
|
str = msi_alloc( (len+1)*sizeof(WCHAR) );
|
||||||
if( !st->strings[n].str )
|
if( !str )
|
||||||
return -1;
|
return -1;
|
||||||
TRACE("%d\n",__LINE__);
|
TRACE("%d\n",__LINE__);
|
||||||
memcpy( st->strings[n].str, data, len*sizeof(WCHAR) );
|
memcpy( str, data, len*sizeof(WCHAR) );
|
||||||
st->strings[n].str[len] = 0;
|
str[len] = 0;
|
||||||
st->strings[n].refcount = 1;
|
|
||||||
st->strings[n].hash = msistring_makehash( st->strings[n].str );
|
|
||||||
|
|
||||||
st_mark_entry_used( st, n );
|
set_st_entry( st, n, str );
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -349,23 +362,19 @@ UINT msi_id2stringA( string_table *st, UINT id, LPSTR buffer, UINT *sz )
|
||||||
*/
|
*/
|
||||||
UINT msi_string2idW( string_table *st, LPCWSTR str, UINT *id )
|
UINT msi_string2idW( string_table *st, LPCWSTR str, UINT *id )
|
||||||
{
|
{
|
||||||
UINT hash;
|
UINT n, hash = msistring_makehash( str );
|
||||||
UINT i, r = ERROR_INVALID_PARAMETER;
|
msistring *se = st->strings;
|
||||||
|
|
||||||
hash = msistring_makehash( str );
|
for (n = st->hash[hash]; n != -1; n = st->strings[n].hash_next )
|
||||||
for( i=0; i<st->maxcount; i++ )
|
|
||||||
{
|
{
|
||||||
if ( (str == NULL && st->strings[i].str == NULL) ||
|
if ((str == se[n].str) || !lstrcmpW(str, se[n].str))
|
||||||
( ( st->strings[i].hash == hash ) &&
|
|
||||||
!strcmpW( st->strings[i].str, str ) ))
|
|
||||||
{
|
{
|
||||||
r = ERROR_SUCCESS;
|
*id = n;
|
||||||
*id = i;
|
return ERROR_SUCCESS;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r;
|
return ERROR_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT msi_string2idA( string_table *st, LPCSTR buffer, UINT *id )
|
UINT msi_string2idA( string_table *st, LPCSTR buffer, UINT *id )
|
||||||
|
|
Loading…
Reference in New Issue