diff options
-rw-r--r-- | channels/chan_agent.c | 11 | ||||
-rw-r--r-- | translate.c | 14 |
2 files changed, 14 insertions, 11 deletions
diff --git a/channels/chan_agent.c b/channels/chan_agent.c index 6bbc89cb3..fb77a9456 100644 --- a/channels/chan_agent.c +++ b/channels/chan_agent.c @@ -1334,12 +1334,13 @@ static struct ast_channel *agent_request(const char *type, int format, void *dat return chan; } -static int powerof(unsigned int v) +static force_inline int powerof(unsigned int d) { - int x; - for (x=0;x<32;x++) { - if (v & (1 << x)) return x; - } + int x = ffs(d); + + if (x) + return x - 1; + return 0; } diff --git a/translate.c b/translate.c index 6bb313871..256130c82 100644 --- a/translate.c +++ b/translate.c @@ -74,13 +74,15 @@ static struct translator_path tr_matrix[MAX_FORMAT][MAX_FORMAT]; */ /*! \brief returns the index of the lowest bit set */ -static int powerof(int d) +static force_inline int powerof(unsigned int d) { - int x; - for (x = 0; x < MAX_FORMAT; x++) - if ((1 << x) & d) - return x; - ast_log(LOG_WARNING, "Powerof %d: No power??\n", d); + int x = ffs(d); + + if (x) + return x - 1; + + ast_log(LOG_WARNING, "No bits set? %d\n", d); + return -1; } |