diff options
author | Glenn Kasten <gkasten@google.com> | 2011-12-15 14:38:29 -0800 |
---|---|---|
committer | Glenn Kasten <gkasten@google.com> | 2012-01-05 15:31:19 -0800 |
commit | 98dd542ffcd3424b1da58bd273c0c1ff5b8c8960 (patch) | |
tree | e3bc2deb104359535cb71f9f728cfb197298cda6 /services/audioflinger/AudioMixer.cpp | |
parent | a2a0a5d7d56baa831870f4bf2a0d942a477d92ef (diff) | |
download | frameworks_av-98dd542ffcd3424b1da58bd273c0c1ff5b8c8960.zip frameworks_av-98dd542ffcd3424b1da58bd273c0c1ff5b8c8960.tar.gz frameworks_av-98dd542ffcd3424b1da58bd273c0c1ff5b8c8960.tar.bz2 |
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
Diffstat (limited to 'services/audioflinger/AudioMixer.cpp')
-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 d994a87..fb1ca87 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; |