Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c1d810d1 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

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
parent a8719ad9
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -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;