[FFmpeg-cvslog] r9808 - trunk/libavformat/utils.c

Måns Rullgård mans
Fri Jul 27 13:59:14 CEST 2007


Alex Beregszaszi <alex at rtfs.hu> writes:

> Hi,
>
>>  enum CodecID codec_get_id(const AVCodecTag *tags, unsigned int tag)
>>  {
>> -    while (tags->id != CODEC_ID_NONE) {
>> -        if(   toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF)
>> -           && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF)
>> -           && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF)
>> -           && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF))
>> -            return tags->id;
>> -        tags++;
>> +    int i;
>> +    for(i=0; tags[i].id != CODEC_ID_NONE;i++) {
>> +        if(tag == tags[i].tag)
>> +            return tags[i].id;
>> +    }
>> +    for(i=0; tags[i].id != CODEC_ID_NONE; i++) {
>> +        if(   toupper((tag >> 0)&0xFF) == toupper((tags[i].tag >> 0)&0xFF)
>> +           && toupper((tag >> 8)&0xFF) == toupper((tags[i].tag >> 8)&0xFF)
>> +           && toupper((tag >>16)&0xFF) == toupper((tags[i].tag >>16)&0xFF)
>> +           && toupper((tag >>24)&0xFF) == toupper((tags[i].tag >>24)&0xFF))
>> +            return tags[i].id;
>
> Why did you cosmetic while -> for change? You go from i=0 thus the while
> and for cycles are the same.

The while loop destroys the original value of tags, which is needed
again at the start of the second loop.  The alternative would be to
use a temporary tags pointer, resetting it to the original value
between the two loops.  Only Michael can tell why he prefers the for
loop.  I don't personally care one way or the other.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-cvslog mailing list