Implemented hash table lookup for RTF keywords in RTF reader.

oldstable
Phil Krylov 2005-03-15 19:31:44 +00:00 committed by Alexandre Julliard
parent 300240bf96
commit bf4dc2e152
2 changed files with 32 additions and 2 deletions

View File

@ -3274,6 +3274,14 @@ static RTFKey rtfKey[] =
{ 0, -1, (char *) NULL, 0 }
};
#define RTF_KEY_COUNT (sizeof(rtfKey) / sizeof(RTFKey))
typedef struct tagRTFHashTableEntry {
int count;
RTFKey **value;
} RTFHashTableEntry;
static RTFHashTableEntry rtfHashTable[RTF_KEY_COUNT];
/*
@ -3287,8 +3295,18 @@ static void LookupInit(void)
if (inited == 0)
{
for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
memset(rtfHashTable, 0, RTF_KEY_COUNT * sizeof(*rtfHashTable));
for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++) {
int index;
rp->rtfKHash = Hash ((char*)rp->rtfKStr);
index = rp->rtfKHash % RTF_KEY_COUNT;
if (!rtfHashTable[index].count)
rtfHashTable[index].value = (void *)RTFAlloc(sizeof(RTFKey *));
else
rtfHashTable[index].value = (void *)RTFReAlloc((void *)rtfHashTable[index].value, sizeof(RTFKey *) * (rtfHashTable[index].count + 1));
rtfHashTable[index].value[rtfHashTable[index].count++] = rp;
}
++inited;
}
}
@ -3303,12 +3321,16 @@ static void Lookup(RTF_Info *info, char *s)
{
RTFKey *rp;
int hash;
RTFHashTableEntry *entry;
int i;
TRACE("\n");
++s; /* skip over the leading \ character */
hash = Hash (s);
for (rp = rtfKey; rp->rtfKStr != (char *) NULL; rp++)
entry = &rtfHashTable[hash % RTF_KEY_COUNT];
for (i = 0; i < entry->count; i++)
{
rp = entry->value[i];
if (hash == rp->rtfKHash && strcmp (s, rp->rtfKStr) == 0)
{
info->rtfClass = rtfControl;
@ -3358,6 +3380,13 @@ char *_RTFAlloc(int size)
}
char *
RTFReAlloc(char *ptr, int size)
{
return HeapReAlloc(me_heap, 0, ptr, size);
}
/*
* Saves a string on the heap and returns a pointer to it.
*/

View File

@ -1533,6 +1533,7 @@ RTFColor *RTFGetColor (RTF_Info *, int);
RTFStyle *RTFGetStyle (RTF_Info *, int);
# define RTFAlloc(size) _RTFAlloc ((int) size)
char *_RTFAlloc (int);
char *RTFReAlloc(char *ptr, int size);
char *RTFStrSave (char *);
void RTFFree (char *);
int RTFCharToHex ( char);