utils: use shift instead of division

We can use a shift for scaling the denominator instead of a divide since the
denom is always positive. This avoids having the compiler generate code for the
different rounding rules when scaling negative values.
This commit is contained in:
Wim Taymans 2009-08-28 15:32:26 +02:00
parent 6cf8948663
commit 378b1e30e7

View file

@ -521,7 +521,7 @@ gst_util_uint64_scale (guint64 val, guint64 num, guint64 denom)
guint64
gst_util_uint64_scale_round (guint64 val, guint64 num, guint64 denom)
{
return _gst_util_uint64_scale (val, num, denom, denom / 2);
return _gst_util_uint64_scale (val, num, denom, denom >> 1);
}
/**
@ -622,7 +622,9 @@ gst_util_uint64_scale_int (guint64 val, gint num, gint denom)
guint64
gst_util_uint64_scale_int_round (guint64 val, gint num, gint denom)
{
return _gst_util_uint64_scale_int (val, num, denom, denom / 2);
/* we can use a shift to divide by 2 because denom is required to be
* positive. */
return _gst_util_uint64_scale_int (val, num, denom, denom >> 1);
}
/**