Changeset 719:c3bf502ba3c3 for charset.c

Show
Ignore:
Timestamp:
1999-01-08 15:29:05 (10 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

When doing a binary search, we may as well use bsearch (3).

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • charset.c

    r703 r719  
    482482static CHARDESC *repr2descr (int repr, CHARSET * cs) 
    483483{ 
    484   size_t a, b, c; 
    485   short found; 
     484  CHARDESC key; 
    486485 
    487486  if (!cs || repr < 0) 
     
    496495  } 
    497496 
    498   /* So we have a multibyte mapping, i.e., Unicode.  */ 
    499  
    500   /* binary search for the proper description */ 
    501   a = 0; 
    502   b = cs->u_symb - 1; 
    503   c = 0;  /* shut up the compiler. */ 
    504   found = 0; 
    505  
    506   while (!found && b - a > 1) 
    507   { 
    508     c = (a + b) / 2; 
    509  
    510     if (cs->description[c]->repr == repr) 
    511     { 
    512       found = 1; 
    513       break; 
    514     } 
    515     else if (cs->description[c]->repr < repr) 
    516       a = c; 
    517     else if (cs->description[c]->repr > repr) 
    518       b = c; 
    519   } 
    520  
    521   if (!found) 
    522   { 
    523     if (cs->description[(c = a)]->repr == repr) 
    524       found = 1; 
    525     else if (cs->description[(c = b)]->repr == repr) 
    526       found = 1; 
    527   } 
    528      
    529   if (found) 
    530   { 
    531     dprint (5, (debugfile, "repr2descr: %x -> { %x, %s }\n", 
    532                 repr, cs->description[c]->repr, cs->description[c]->symbol)); 
    533     return cs->description[c]; 
    534   } 
    535   else 
    536     dprint (5, (debugfile, "Couldn't file a symbol for %x\n", 
    537                 repr)); 
    538  
    539   return NULL; 
     497  key.repr = repr; 
     498  return bsearch (&key, cs->description, cs->u_symb, 
     499                  sizeof (CHARDESC *), _cd_compar); 
    540500} 
    541501