Changeset 3669 for trunk


Ignore:
Timestamp:
Sep 19, 2010, 2:23:16 AM (15 years ago)
Author:
bird
Message:

grow.h/c: Store the string length, speeds up collition handling and adds strpool_len() for skipping strlen()'s. Fixed strpool_addnu/strpool_addu matching bug.

Location:
trunk/emx/src/emxomf
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/emx/src/emxomf/grow.c

    r492 r3669  
    3737#include <string.h>
    3838#include <ctype.h>
     39#include <assert.h>
    3940#include "defs.h"
    4041#include "grow.h"
     
    250251{
    251252  struct string *next;          /* Pointer to next string in same bucket */
     253  int len;                      /* The string length. */
    252254  char string[1];               /* The string */
    253255};
     
    310312  hash %= STRPOOL_HASH_SIZE;
    311313  for (v = p->table[hash]; v != NULL; v = v->next)
    312     if (strlen (v->string) == len && memcmp (v->string, s, len) == 0)
     314    if (v->len == len && memcmp (v->string, s, len) == 0)
    313315      return v->string;
    314316  v = xmalloc (sizeof (*v) + len);
     317  assert(((uintptr_t)v & (sizeof(int) - 1)) == 0);
    315318  memcpy (v->string, s, len);
    316319  v->string[len] = 0;
     320  v->len = len;
    317321  v->next = p->table[hash];
    318322  p->table[hash] = v;
     
    348352  hash %= STRPOOL_HASH_SIZE;
    349353  for (v = p->table[hash]; v != NULL; v = v->next)
    350     if (strlen (v->string) == len && memcmp (v->string, s, len) == 0)
    351       return v->string;
     354    if (v->len == len)
     355      {
     356        i = len;
     357        while (--i >= 0)
     358          if (toupper(s[i]) != v->string[i])
     359            break;
     360        if (i < 0)
     361            return v->string;
     362      }
    352363  v = xmalloc (sizeof (*v) + len);
     364  assert(((uintptr_t)v & (sizeof(int) - 1)) == 0);
    353365  memcpy (v->string, s, len);
    354366  v->string[len] = 0;
    355   strupr(v->string);
     367  v->len = len;
     368  strupr (v->string);
    356369  v->next = p->table[hash];
    357370  p->table[hash] = v;
     
    369382}
    370383
     384/* Get the length of a string pool string.  This is very quick since we store
     385   the lenght before the string data.  */
     386int strpool_len (const char *s)
     387{
     388    assert(((uintptr_t)s & (sizeof(int) - 1)) == 0);
     389    if (!s)
     390      return 0;
     391    return ((size_t *)s)[-1];
     392}
     393
  • trunk/emx/src/emxomf/grow.h

    r492 r3669  
    5959const char *strpool_addn (struct strpool *p, const char *s, int len);
    6060const char *strpool_add (struct strpool *p, const char *s);
    61 const char *strpool_addnu ( struct strpool *p, const char *s, int len);
    62 const char *strpool_addu ( struct strpool *p, const char *s);
     61const char *strpool_addnu (struct strpool *p, const char *s, int len);
     62const char *strpool_addu (struct strpool *p, const char *s);
     63int strpool_len (const char *s);
     64
Note: See TracChangeset for help on using the changeset viewer.