Changeset 9907


Ignore:
Timestamp:
Jan 10, 2010, 2:56:04 PM (12 years ago)
Author:
livings124
Message:

random code optimization: when escaping http, use an if with a lot less comparisons rather than a switch

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/web.c

    r9906 r9907  
    515515
    516516    for( i = 0; i < len; i++ ) {
    517         switch( str[i] ) {
    518         case ',': case '-': case '.':
    519         case '0': case '1': case '2': case '3': case '4':
    520         case '5': case '6': case '7': case '8': case '9':
    521         case 'a': case 'b': case 'c': case 'd': case 'e':
    522         case 'f': case 'g': case 'h': case 'i': case 'j':
    523         case 'k': case 'l': case 'm': case 'n': case 'o':
    524         case 'p': case 'q': case 'r': case 's': case 't':
    525         case 'u': case 'v': case 'w': case 'x': case 'y': case 'z':
    526         case 'A': case 'B': case 'C': case 'D': case 'E':
    527         case 'F': case 'G': case 'H': case 'I': case 'J':
    528         case 'K': case 'L': case 'M': case 'N': case 'O':
    529         case 'P': case 'Q': case 'R': case 'S': case 'T':
    530         case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
     517        if( str[i] == ',' || str[i] == '-' || str[i] == '.'
     518            || ( '0' <= str[i] && str[i] <= '9' )
     519            || ( 'a' <= str[i] && str[i] <= 'z' )
     520            || ( 'A' <= str[i] && str[i] <= 'Z' )
     521            || ( str[i] == '/' && !escape_slashes ) )
    531522            evbuffer_add( out, &str[i], 1 );
    532             break;
    533         case '/':
    534             if(!escape_slashes) {
    535                 evbuffer_add( out, &str[i], 1 );
    536                 break;
    537             }
    538             /* Fall through. */
    539         default:
     523        else
    540524            evbuffer_add_printf( out, "%%%02X", (unsigned)(str[i]&0xFF) );
    541             break;
    542         }
    543525    }
    544526}
Note: See TracChangeset for help on using the changeset viewer.