# HG changeset patch # User reimar # Date 1189802250 0 # Node ID e24dd407fb58dbb6853a5bff27706964f44526f9 # Parent e5eb9ccd667949e44e07901b6880e81870d8e468 Optimize demux_ty_FindESHeader diff -r e5eb9ccd6679 -r e24dd407fb58 libmpdemux/demux_ty.c --- a/libmpdemux/demux_ty.c Fri Sep 14 20:18:00 2007 +0000 +++ b/libmpdemux/demux_ty.c Fri Sep 14 20:37:30 2007 +0000 @@ -356,14 +356,15 @@ static int demux_ty_FindESHeader( unsigned char *header, unsigned char *buffer, int bufferSize ) { - int count; - for( count = 0 ; count + 3 < bufferSize ; count++ ) - { - if ( buffer[ count + 0 ] == header[ 0 ] && - buffer[ count + 1 ] == header[ 1 ] && - buffer[ count + 2 ] == header[ 2 ] && - buffer[ count + 3 ] == header[ 3 ] ) - return count; + uint32_t search = AV_RB32(header); + uint32_t found = -1; + uint8_t *p = buffer; + uint8_t *end = p + bufferSize; + while (p < end) { + found <<= 8; + found |= *p++; + if (found == search) + return p - buffer - 4; } return -1; }