VirtualBox

Changeset 23586 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Oct 6, 2009 4:52:20 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53252
Message:

CFGM: Sort the key and value name so that ordering is predictable. (device creation order.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/CFGM.cpp

    r22526 r23586  
    340340
    341341/**
     342 * Compares two names.
     343 *
     344 * @returns Similar to memcpy.
     345 * @param   pszName1            The first name.
     346 * @param   cchName1            The length of the first name.
     347 * @param   pszName2            The second name.
     348 * @param   cchName2            The length of the second name.
     349 */
     350DECLINLINE(int) cfgmR3CompareNames(const char *pszName1, size_t cchName1, const char *pszName2, size_t cchName2)
     351{
     352    int iDiff;
     353    if (cchName1 <= cchName2)
     354    {
     355        iDiff = memcmp(pszName1, pszName2, cchName1);
     356        if (!iDiff && cchName1 < cchName2)
     357            iDiff = -1;
     358    }
     359    else
     360    {
     361        iDiff = memcmp(pszName1, pszName2, cchName2);
     362        if (!iDiff)
     363            iDiff = 1;
     364    }
     365    return iDiff;
     366}
     367
     368
     369/**
    342370 * Validates that the child nodes are within a set of valid names.
    343371 *
     
    10311059            RTUINT cchName = pszNext - pszPath;
    10321060
    1033             /* search child list. */
     1061            /* search child list. */ /** @todo the list is ordered now, consider optimizing the search. */
    10341062            pChild = pNode->pFirstChild;
    10351063            for ( ; pChild; pChild = pChild->pNext)
     
    10711099        while (pLeaf)
    10721100        {
     1101            /** @todo the list is ordered now, consider optimizing the search. */
    10731102            if (    cchName == pLeaf->cchName
    10741103                && !memcmp(pszName, pLeaf->szName, cchName) )
     
    12521281             * Check if already exists and find last node in chain.
    12531282             */
    1254             size_t cchName = strlen(pszName);
    1255             PCFGMNODE pPrev = pNode->pFirstChild;
    1256             if (pPrev)
     1283            size_t    cchName = strlen(pszName);
     1284            PCFGMNODE pPrev   = NULL;
     1285            PCFGMNODE pNext   = pNode->pFirstChild;
     1286            if (pNext)
    12571287            {
    1258                 for (;; pPrev = pPrev->pNext)
     1288                for (; pNext; pPrev = pNext, pNext = pNext->pNext)
    12591289                {
    1260                     if (    cchName == pPrev->cchName
    1261                         &&  !memcmp(pszName, pPrev->szName, cchName))
    1262                         return VERR_CFGM_NODE_EXISTS;
    1263                     if (!pPrev->pNext)
     1290                    int iDiff = cfgmR3CompareNames(pszName, cchName, pNext->szName, pNext->cchName);
     1291                    if (iDiff <= 0)
     1292                    {
     1293                        if (!iDiff)
     1294                            return VERR_CFGM_NODE_EXISTS;
    12641295                        break;
     1296                    }
    12651297                }
    12661298            }
     
    12831315                 * Insert into child list.
    12841316                 */
    1285                 pNew->pNext         = NULL;
    12861317                pNew->pPrev         = pPrev;
    12871318                if (pPrev)
     
    12891320                else
    12901321                    pNode->pFirstChild = pNew;
     1322                pNew->pNext         = pNext;
     1323                if (pNext)
     1324                    pNext->pPrev    = pNew;
     1325
    12911326                if (ppChild)
    12921327                    *ppChild = pNew;
     
    13881423             * Check if already exists and find last node in chain.
    13891424             */
    1390             size_t cchName = strlen(pszName);
    1391             PCFGMLEAF pPrev = pNode->pFirstLeaf;
    1392             if (pPrev)
     1425            size_t    cchName  = strlen(pszName);
     1426            PCFGMLEAF pPrev    = NULL;
     1427            PCFGMLEAF pNext    = pNode->pFirstLeaf;
     1428            if (pNext)
    13931429            {
    1394                 for (;; pPrev = pPrev->pNext)
     1430                for (; pNext; pPrev = pNext, pNext = pNext->pNext)
    13951431                {
    1396                     if (    cchName == pPrev->cchName
    1397                         &&  !memcmp(pszName, pPrev->szName, cchName))
    1398                         return VERR_CFGM_LEAF_EXISTS;
    1399                     if (!pPrev->pNext)
     1432                    int iDiff = cfgmR3CompareNames(pszName, cchName, pNext->szName, pNext->cchName);
     1433                    if (iDiff <= 0)
     1434                    {
     1435                        if (!iDiff)
     1436                            return VERR_CFGM_LEAF_EXISTS;
    14001437                        break;
     1438                    }
    14011439                }
    14021440            }
     
    14141452                 * Insert into child list.
    14151453                 */
    1416                 pNew->pNext         = NULL;
    14171454                pNew->pPrev         = pPrev;
    14181455                if (pPrev)
     
    14201457                else
    14211458                    pNode->pFirstLeaf = pNew;
     1459                pNew->pNext         = pNext;
     1460                if (pNext)
     1461                    pNext->pPrev    = pNew;
     1462
    14221463                *ppLeaf = pNew;
    14231464                rc = VINF_SUCCESS;
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