VirtualBox

Changeset 37642 in vbox


Ignore:
Timestamp:
Jun 27, 2011 4:51:13 AM (13 years ago)
Author:
vboxsync
Message:

Audio/HDA: some todo (binary search).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Audio/DevIchIntelHDA.cpp

    r37639 r37642  
    735735static int hdaLookup(INTELHDLinkState* pState, uint32_t u32Offset)
    736736{
    737     /// @todo r=michaln: A linear search of an array with over 100 elements is very inefficient.
    738     /** @todo r=bird: Do a binary search, the array is sorted. */
    739     for (int index = 0; index < (int)RT_ELEMENTS(s_ichIntelHDRegMap); ++index)
    740     {
    741         if (   u32Offset >= s_ichIntelHDRegMap[index].offset
    742             && u32Offset < s_ichIntelHDRegMap[index].offset + s_ichIntelHDRegMap[index].size)
    743         {
    744             return index;
    745         }
     737    int idxMiddle;
     738    int idxHigh = RT_ELEMENTS(s_ichIntelHDRegMap);
     739    int idxLow = 0;
     740    while (1)
     741    {
     742            if (idxHigh < idxLow)
     743                break;
     744            idxMiddle = idxLow + (idxHigh - idxLow)/2;
     745            if (u32Offset < s_ichIntelHDRegMap[idxMiddle].offset)
     746            {
     747                idxHigh = idxMiddle - 1;
     748                continue;
     749            }
     750            if (u32Offset >= s_ichIntelHDRegMap[idxMiddle].offset + s_ichIntelHDRegMap[idxMiddle].size)
     751            {
     752                idxLow = idxMiddle + 1;
     753                continue;
     754            }
     755            if (u32Offset >= s_ichIntelHDRegMap[idxMiddle].offset
     756                && u32Offset < s_ichIntelHDRegMap[idxMiddle].offset + s_ichIntelHDRegMap[idxMiddle].size)
     757                return idxMiddle;
    746758    }
    747759    /* Aliases HDA spec 3.3.45 */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette