diff options
author | Lennart Poettering <lennart@poettering.net> | 2007-08-22 17:05:41 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2007-08-22 17:05:41 +0000 |
commit | 044996685258c69e120de7198b3cfbb96faa50ba (patch) | |
tree | c16746adb9d52a6242d1ad055575395f33f3e1bd /src/pulsecore/core-util.h | |
parent | 190648a3ed1267896083a24dbb27d7552104ca00 (diff) |
make pa_make_power_of_two() and pa_is_power_of_two() inline functions
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1698 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/pulsecore/core-util.h')
-rw-r--r-- | src/pulsecore/core-util.h | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h index 29dc2fb1..ea571e70 100644 --- a/src/pulsecore/core-util.h +++ b/src/pulsecore/core-util.h @@ -97,7 +97,22 @@ int pa_snprintf(char *str, size_t size, const char *format, ...); char *pa_truncate_utf8(char *c, size_t l); -int pa_is_power_of_two(unsigned n); -unsigned pa_make_power_of_two(unsigned n); +static inline int pa_is_power_of_two(unsigned n) { + return !(n & (n - 1)); +} + +static inline unsigned pa_make_power_of_two(unsigned n) { + unsigned j = n; + + if (pa_is_power_of_two(n)) + return n; + + while (j) { + j = j >> 1; + n = n | j; + } + + return n + 1; +} #endif |