VirtualBox

Changeset 98082 in vbox


Ignore:
Timestamp:
Jan 15, 2023 1:59:48 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155214
Message:

Main/ConsoleImpl: Optimized the getDeviceActivity code a little by replacing two std::vector objects with fixed sized arrays of 8 elements each. To facilitate this DeviceType got a new final 'End' value added. Also missing validation of the aType values. Result is ~30% smaller code. bugref:9892

Location:
trunk/src/VBox/Main
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/idl/VirtualBox.xidl

    r98044 r98082  
    13251325    <const name="Graphics3D"        value="7">
    13261326      <desc>Graphics device 3D activity.</desc>
     1327    </const>
     1328    <const name="End"               value="8">
     1329      <desc>End of valid device types (exclusive).  Used for invalid validation and such.</desc>
    13271330    </const>
    13281331  </enum>
  • trunk/src/VBox/Main/src-client/ConsoleImpl.cpp

    r97815 r98082  
    28322832     */
    28332833
    2834     std::vector<bool> aWanted;
    2835     std::vector<PDMLEDCORE> aLED;
    2836     DeviceType_T maxWanted = (DeviceType_T) 0;
    2837     DeviceType_T enmType;
    2838 
    28392834    /* Make a roadmap of which DeviceType_T LED types are wanted */
     2835    DeviceType_T maxWanted = (DeviceType_T)0;
     2836    bool aWanted[DeviceType_End] = { 0 };
     2837    Assert(aWanted[1] == false && aWanted[DeviceType_End - 1] == false);
     2838
    28402839    for (size_t iType = 0; iType < aType.size(); ++iType)
    28412840    {
    2842         enmType = aType[iType];
     2841        DeviceType_T const enmType = aType[iType];
     2842        AssertReturn(enmType > DeviceType_Null && enmType < DeviceType_End,
     2843                     setError(E_INVALIDARG, tr("Invalid DeviceType for getDeviceActivity in entry #%u: %d"), iType, enmType));
     2844        aWanted[enmType] = true;
    28432845        if (enmType > maxWanted)
    2844         {
    28452846            maxWanted = enmType;
    2846             aWanted.resize(maxWanted + 1);
    2847         }
    2848         aWanted[enmType] = true;
    2849     }
    2850     aLED.resize(maxWanted + 1);
     2847    }
     2848
     2849    /* Resize the result vector before making changes (may throw, paranoia). */
     2850    aActivity.resize(aType.size());
    28512851
    28522852    /* Collect all the LEDs in a single sweep through all drivers' sets */
     2853    PDMLEDCORE aLEDs[DeviceType_End] = { {0} };
     2854    Assert(aLEDs[1].u32 == 0 && aLEDs[DeviceType_End / 2].u32 == 0 && aLEDs[DeviceType_End - 1].u32 == 0); /* paranoia */
    28532855    for (uint32_t idxSet = 0; idxSet < mcLedSets; ++idxSet)
    28542856    {
     
    28612863            for (uint32_t inSet = 0; inSet < pLS->cLeds; ++inSet)
    28622864            {
    2863                 enmType = pLS->paSubTypes[inSet];
     2865                DeviceType_T const enmType = pLS->paSubTypes[inSet];
    28642866                if (enmType < maxWanted && aWanted[enmType])
    2865                     aLED[enmType].u32 |= readAndClearLed(pLS->papLeds[inSet]);
     2867                    aLEDs[enmType].u32 |= readAndClearLed(pLS->papLeds[inSet]);
    28662868            }
    28672869        }
     
    28692871        else
    28702872        {
    2871             enmType = pLS->enmType;
     2873            DeviceType_T const enmType = pLS->enmType;
    28722874            if (enmType < maxWanted && aWanted[enmType])
    28732875                for (uint32_t inSet = 0; inSet < pLS->cLeds; ++inSet)
    2874                     aLED[enmType].u32 |= readAndClearLed(pLS->papLeds[inSet]);
    2875         }
    2876     }
    2877 
    2878     aActivity.resize(aType.size());
     2876                    aLEDs[enmType].u32 |= readAndClearLed(pLS->papLeds[inSet]);
     2877        }
     2878    }
     2879
     2880    /* Compose the result vector: */
    28792881    for (size_t iType = 0; iType < aActivity.size(); ++iType)
    28802882    {
    2881         /* Compose the result */
    2882         switch (aLED[aType[iType]].u32 & (PDMLED_READING | PDMLED_WRITING))
     2883        switch (aLEDs[aType[iType]].u32 & (PDMLED_READING | PDMLED_WRITING))
    28832884        {
    28842885            case 0:
  • trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp

    r97716 r98082  
    671671    Assert(cLeds > 0);
    672672    Assert(cLeds < 1024);  /* Adjust if any driver supports >=1024 units! */
     673    Assert(enmType > DeviceType_Null && enmType < DeviceType_End);
    673674
    674675    /* Grab a LED set entry before we start allocating anything so the destructor can do the cleanups. */
Note: See TracChangeset for help on using the changeset viewer.

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