Changeset 392


Ignore:
Timestamp:
Jul 16, 2003, 2:05:20 AM (22 years ago)
Author:
bird
Message:

#456: good idea to use the right next pointer when walking a chain.

File:
1 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.15 to 1.16
    r391 r392  
    2020Boston, MA 02111-1307, USA.  */
    2121
    22 #define HASH_DEBUG
    2322
    2423/*******************************************************************************
     
    298297
    299298static struct type *type_head;
    300 #define TYPE_HASH_MAX   128
     299#define TYPE_HASH_MAX   211
    301300static struct type *atype_tag[TYPE_HASH_MAX];
    302301#ifdef HASH_DEBUG
     
    575574 * @param   t     type
    576575 */
    577 static unsigned type_hash (struct type *t)
     576static inline unsigned type_hash (struct type *t)
    578577{
    579578  register unsigned uhash = 0;
    580   unsigned          uret;
    581579  switch (t->tag)
    582580    {
     
    591589      case ty_array:        uhash = (unsigned)t->d.array.etype; break;
    592590      case ty_bits:         uhash = (unsigned)t->d.bits.type; break;
    593       case ty_func:         uhash = (unsigned)t->d.func.args; break;
    594       case ty_types:        uhash = (unsigned)t->d.types.count  <<2; break;
    595       case ty_args:         uhash = (unsigned)t->d.args.count   <<2; break;
    596       case ty_fields:       uhash = (unsigned)t->d.fields.count <<2; break;
    597       case ty_member:       uhash = (unsigned)t->d.member.type; break;
    598       case ty_values:       uhash = (unsigned)t->d.values.count <<2; break;
     591      case ty_func:         uhash = (unsigned)t->d.func.args ^ (unsigned)t->d.func.arg_count ^ (unsigned)t->d.func.ret ^ (unsigned)t->d.func.domain; break;
     592      case ty_types:        uhash = (unsigned)t->d.types.count  << 3; break;
     593      case ty_args:         uhash = (unsigned)t->d.args.count   << 3; break;
     594      case ty_fields:       uhash = (unsigned)t->d.fields.count << 3; break;
     595      case ty_member:       uhash = (unsigned)t->d.member.type ^ (unsigned)t->d.member.name >> 7; break;
     596      case ty_values:       uhash = (unsigned)t->d.values.count << 3; break;
    599597      case ty_memfunc:      uhash = (unsigned)t->d.memfunc.type; break;
    600598      case ty_baseclass:    uhash = (unsigned)t->d.baseclass.type; break;
    601599    }
    602600  uhash += t->tag;
    603   uret = uhash ^ (uhash >> 13);
    604   return uret & (TYPE_HASH_MAX - 1);
    605 }
    606 
    607 
    608 /* Add a new internal type to the list of internal types.  If an
    609    identical type already exists, a pointer to that type is returned.
    610    Otherwise, a copy of the new type is added to the list and a
    611    pointer to that type is returned.  It isn't worth my while to
    612    improve the speed of this function, for instance by using
    613    hashing.
    614 
    615    Actually it is worth while optimizing it as it takes 85% of the
    616    time here... or rather it was. */
    617 
    618 static struct type *type_add (struct type *src)
    619 {
    620   unsigned ihash;
    621   struct type *p;
     601  return (uhash ^ uhash >> 13) % TYPE_HASH_MAX;
     602}
     603
     604
     605/**
     606 * Search a list for a type.
     607 * @returns pointer to the type we found.
     608 * @returns NULL if not found.
     609 * @param   p       Pointer to the head list.
     610 * @param   src     Type to find.
     611 * @param   fhash   Whether or not to follow the hash list or the main list.
     612 */
     613#ifdef HASH_DEBUG
     614static struct type *type_find (struct type *p, const struct type *src, int fhash)
     615#else
     616static struct type *type_find (struct type *p, const struct type *src)
     617#endif
     618{
    622619  int i;
    623 
    624   ihash = type_hash(src);
    625   for (p = atype_tag[ihash]; p != NULL; p = p->nexthash)
     620  for (; p != NULL;
     621#ifdef HASH_DEBUG
     622       p = fhash ? p->nexthash : p->next )
     623#else
     624       p = p->nexthash                   )
     625#endif
    626626    if (p->tag == src->tag)
    627627      switch (p->tag)
     
    752752          abort ();
    753753        }
    754 
     754  return NULL;
     755}
     756
     757
     758/* Add a new internal type to the list of internal types.  If an
     759   identical type already exists, a pointer to that type is returned.
     760   Otherwise, a copy of the new type is added to the list and a
     761   pointer to that type is returned.  It isn't worth my while to
     762   improve the speed of this function, for instance by using
     763   hashing.
     764
     765   Actually it is worth while optimizing it as it takes 85% of the
     766   time here... or rather it was.
     767
     768   ctypes=25301 */
     769
     770static struct type *type_add (struct type *src)
     771{
     772  struct type *p;
     773  unsigned ihash;
     774  int i;
     775
     776  ihash = type_hash(src);
    755777#ifdef HASH_DEBUG
     778  p = type_find (atype_tag[ihash], src, 1);
     779#else
     780  p = type_find (atype_tag[ihash], src);
     781#endif
     782  if (p)
     783    {
     784      return p;
     785    }
     786
     787#ifdef HASH_DEBUG
     788/*  {
     789    struct type *pcheck = type_find (type_head, src, 0);
     790    if (pcheck)
     791      {
     792        printf("\n\thash algorithm is borked! tag=%d\n", pcheck->tag);
     793        return pcheck;
     794      }
     795  } */
     796  ctype_tag[ihash]++;
    756797  ctypes++;
    757   ctype_tag[ihash]++;
    758798#endif
    759799
     
    14551495static const char *nextcolon(const char *psz)
    14561496{
    1457     int cNesting;                       /* <> level */
    1458 
    1459     for (cNesting = 0;;psz++)
    1460       switch (*psz)
    1461         {
    1462           case '<':
    1463             #if 0
    1464             /* workaround for "operator<::" and "operator<::"
    1465              *  */
    1466             if (!cNesting  || (psz[1] == ':' && psz[2] == ':'))
    1467                 return psz + 1;
    1468             if (!cNesting  || (psz[1] == '<' && psz[2] == ':' && psz[3] == ':'))
    1469                 return psz + 2;
    1470             #else
    1471             /* general and faster check: < or > followed by : means the end. */
    1472             #endif
    1473             if (psz[1] == ':')
    1474               return psz + 1;
    1475             cNesting++;
    1476             break;
    1477           case '>':
    1478             if (psz[1] == ':')
    1479               return psz + 1;
    1480             cNesting--;
    1481             break;
    1482           case ':':
    1483             if (cNesting <= 0)
    1484               return psz;
    1485             break;
    1486           case '\0':
    1487             return NULL;
    1488         }
    1489       psz++;
    1490 
    1491     return NULL;
     1497  int cNesting = 0;                     /* <> level */
     1498
     1499  for (;;psz++)
     1500    switch (*psz)
     1501      {
     1502        case '<':
     1503          if (psz[1] == ':')
     1504            return psz + 1;
     1505          cNesting++;
     1506          break;
     1507        case '>':
     1508          if (psz[1] == ':')
     1509            return psz + 1;
     1510          cNesting--;
     1511          break;
     1512        case ':':
     1513          if (cNesting <= 0)
     1514            return psz;
     1515          break;
     1516        case '\0':
     1517          return NULL;
     1518      }
     1519  return NULL;
    14921520}
    14931521
     
    35943622
    35953623#ifdef HASH_DEBUG
     3624fprintf(stderr, "\n");
    35963625for (i = 0; i < TYPE_HASH_MAX; i++)
    35973626  if (i % 7 == 6)
     
    36003629    fprintf(stderr, "%3d: %4d   ", i, ctype_tag[i]);
    36013630fprintf(stderr, "\nctypes=%d\n", ctypes);
     3631for (i = 0; i < TYPE_HASH_MAX; i++)
     3632  if (ctype_tag[i] > 1000)
     3633    {
     3634      int       j;
     3635      unsigned  au[ty_max];
     3636      memset(&au[0], 0, sizeof(au));
     3637      for (t1 = atype_tag[i]; t1 != NULL; t1 = t1->nexthash)
     3638        au[t1->tag]++;
     3639
     3640      fprintf(stderr, "\nIndex %d is overpopulated (%d):\n", i, ctype_tag[i]);
     3641      for (j = 0; j < 18; j++)
     3642        if (j % 7 == 6)
     3643          fprintf(stderr, "%2d: %4d\n", j, au[j]);
     3644        else
     3645          fprintf(stderr, "%2d: %4d   ", j, au[j]);
     3646    }
    36023647#endif
    36033648
Note: See TracChangeset for help on using the changeset viewer.