Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.c++.moderated    |    Moderated discussion of C++ superhackery    |    33,346 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 31,959 of 33,346    |
|    James K. Lowden to All    |
|    justifiable, ancient, or silly?    |
|    29 Feb 12 03:54:16    |
   
   From: jklowden@speakeasy.net   
      
   I recently came across code testing passed strings that I'm guessing is   
   intended to be fast, but to me looks just awful. Before I   
   suggest/offer fixes, I want to make sure I'm not missing something   
   obvious.   
      
   The function is passed a length and a char*, and does:   
      
   switch(len) {   
   case 5:   
    if( s[0] == 'H'   
    && s[1] == 'E'   
    && s[2] == 'L'   
    && s[3] == 'L'   
    && s[4] == 'O' )   
    /* stuff*/   
    break;   
   case 8:   
    if( s[0] == 'R'   
    && /* etc. */   
   }   
      
   I can think of three ways in a minute to write that more concisely and   
   idiomatically. The question is, is there now or was there ever   
   justification for such elaborate hard-coding?   
      
   I remember unrolling loops 20 years ago; even then I thought that was   
   the compiler's job. These days size is all because cache is king.   
      
   --jkl   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca