mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-03-30 20:33:08 +02:00
Merge branch 'optimize_g_nearest_pow' into 'master'
Optimize g_nearest_pow() function in glib/garray.c Closes #83 See merge request GNOME/glib!1030
This commit is contained in:
commit
c21892ee13
@ -874,12 +874,20 @@ g_array_binary_search (GArray *array,
|
|||||||
static guint
|
static guint
|
||||||
g_nearest_pow (guint num)
|
g_nearest_pow (guint num)
|
||||||
{
|
{
|
||||||
guint n = 1;
|
guint n = num - 1;
|
||||||
|
|
||||||
while (n < num && n > 0)
|
g_assert (num > 0);
|
||||||
n <<= 1;
|
|
||||||
|
|
||||||
return n ? n : num;
|
n |= n >> 1;
|
||||||
|
n |= n >> 2;
|
||||||
|
n |= n >> 4;
|
||||||
|
n |= n >> 8;
|
||||||
|
n |= n >> 16;
|
||||||
|
#if GLIB_SIZEOF_INT == 8
|
||||||
|
n |= n >> 32;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return n + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user