[FFmpeg-devel] Realmedia patch

Ronald S. Bultje rsbultje
Wed Aug 27 13:53:14 CEST 2008


Hi Benoit,

On Wed, Aug 27, 2008 at 3:24 AM, Benoit Fouet
<benoit.fouet at purplelabs.com> wrote:
> Ronald S. Bultje wrote:
>> Index: ffmpeg-svn/libavformat/utils.c
>> ===================================================================
>> --- ffmpeg-svn.orig/libavformat/utils.c       2008-08-26 20:54:36.000000000 -0400
>> +++ ffmpeg-svn/libavformat/utils.c    2008-08-26 21:01:48.000000000 -0400
>> @@ -3206,25 +3206,18 @@
>>      }
>>  }
>>
>> -static void digit_to_char(char *dst, uint8_t src)
>> -{
>> -    if (src < 10) {
>> -        *dst = '0' + src;
>> -    } else {
>> -        *dst = 'A' + src - 10;
>> -    }
>> -}
>> -
>>  char *ff_data_to_hex(char *buff, const uint8_t *src, int s)
>>  {
>>      int i;
>> +    const char hex_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
>> +                                 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
>>
>> -    for(i = 0; i < s; i++) {
>> -        digit_to_char(buff + 2 * i, src[i] >> 4);
>> -        digit_to_char(buff + 2 * i + 1, src[i] & 0xF);
>> +    for (i = 0; i < s; i++) {
>> +        buff[i * 2]     = hex_table[src[i] >> 4];
>> +        buff[i * 2 + 1] = hex_table[src[i] & 0xF];
>>
>
> did you try with *buff++ too ?
> and return buff - s * 2 + 1

I tried the following:

    int i;
    char *orig_buf = buf;
    const char hex_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7',
                                 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

    for (i = 0; i < size; i++) {
        *buf++ = hex_table[src[i] >> 4];
        *buf++ = hex_table[src[i] & 0xF];
    }

    return orig_buf;

gcc -O0:

old:
real    0m2.375s
user    0m2.352s
sys     0m0.007s

new, original
real    0m0.899s
user    0m0.893s
sys     0m0.005s

new, with your modifications
real    0m0.861s
user    0m0.856s
sys     0m0.005s

gcc -O2:

old:
real    0m1.205s
user    0m1.198s
sys     0m0.007s

new, original:
real    0m0.258s
user    0m0.253s
sys     0m0.004s

new, with your modifications:
real    0m0.260s
user    0m0.255s
sys     0m0.005s

I guess at -O2 it doesn't really make any difference. Is that worth
it? (I don't know the performance policy because I'm not really good
at this stuff. :-) )

>>      }
>>
>> -    return buff;
>> +    return buf
>>
>
> oops ? :)

Oops, fixed locally, not sure how that crept in...

Thanks,
Ronald




More information about the ffmpeg-devel mailing list