diff options
| author | 2011-12-15 14:38:29 -0800 | |
|---|---|---|
| committer | 2012-01-05 15:31:19 -0800 | |
| commit | c1d810d1d0c38ba14d3f7d21d381bcbda649a0fb (patch) | |
| tree | 6e8c6876cf21d86a7e73eeba9492a547a3bc6c8a | |
| parent | a8719ad9d53d3fe51e8031b2471e9558b8ef727f (diff) | |
Replace loop by __builtin_ctz
Using the builtin is faster on some platforms, for example on ARM it's
19 instructions instead of 13, and is O(1) instead of O(n). Of course,
track creation is an inherently slow operation, so this doesn't matter
much now. But if we add support for virtual tracks, then physical tracks
will be allocated/freed more frequently. Also just on principle ...
Change-Id: I3f590934092bd7a1869cbedbc7357928aa5cc8ff
| -rw-r--r-- | services/audioflinger/AudioMixer.cpp | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp index d994a87d88ea..fb1ca8766eb3 100644 --- a/services/audioflinger/AudioMixer.cpp +++ b/services/audioflinger/AudioMixer.cpp @@ -95,16 +95,11 @@ AudioMixer::~AudioMixer() int AudioMixer::getTrackName() { - uint32_t names = mTrackNames; - uint32_t mask = 1; - int n = 0; - while (names & mask) { - mask <<= 1; - n++; - } - if (mask) { + uint32_t names = ~mTrackNames; + if (names != 0) { + int n = __builtin_ctz(names); ALOGV("add track (%d)", n); - mTrackNames |= mask; + mTrackNames |= 1 << n; return TRACK0 + n; } return -1; |