[mythtv] Ticket #7759

Jim Stichnoth stichnot at gmail.com
Sun Dec 20 18:26:28 UTC 2009


On Sun, Dec 20, 2009 at 7:44 AM, Daniel Kristjansson
<danielk at cuymedia.net> wrote:
> On Sun, 2009-12-20 at 15:45 +1100, Davin McCall wrote:
>
>> |2566:         repeat_delay = frame_int_erval * buffer->repeat_pict *
>> 0.5;_|
>
>>      repeat_delay = frame_interval / 2 * buffer->repeat_pict;
>
> I'm revoking your programmers license :) You should never ever use a
> division when a multiply will do. Maybe >>1 is what you meant to
> say? It avoids the conversion from int to double that 0.5 forces.

Well, any decent optimizing compiler will use a shift operation for
dividing by a power of two.  Since frame_interval is declared as int
instead of unsigned, there will be an extra comparison and conditional
branch before the shift, but the branch predictor will make the
conditional branch essentially free if it is hot code.  Also, the
optimizer would probably change a divide by a constant into a multiply
by a constant.  I prefer the straightforward divide-by-2 for
readability.

Jim


More information about the mythtv-dev mailing list