Changeset 23586 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Oct 6, 2009 4:52:20 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 53252
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/CFGM.cpp
r22526 r23586 340 340 341 341 /** 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 */ 350 DECLINLINE(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 /** 342 370 * Validates that the child nodes are within a set of valid names. 343 371 * … … 1031 1059 RTUINT cchName = pszNext - pszPath; 1032 1060 1033 /* search child list. */ 1061 /* search child list. */ /** @todo the list is ordered now, consider optimizing the search. */ 1034 1062 pChild = pNode->pFirstChild; 1035 1063 for ( ; pChild; pChild = pChild->pNext) … … 1071 1099 while (pLeaf) 1072 1100 { 1101 /** @todo the list is ordered now, consider optimizing the search. */ 1073 1102 if ( cchName == pLeaf->cchName 1074 1103 && !memcmp(pszName, pLeaf->szName, cchName) ) … … 1252 1281 * Check if already exists and find last node in chain. 1253 1282 */ 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) 1257 1287 { 1258 for (; ; pPrev = pPrev->pNext)1288 for (; pNext; pPrev = pNext, pNext = pNext->pNext) 1259 1289 { 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; 1264 1295 break; 1296 } 1265 1297 } 1266 1298 } … … 1283 1315 * Insert into child list. 1284 1316 */ 1285 pNew->pNext = NULL;1286 1317 pNew->pPrev = pPrev; 1287 1318 if (pPrev) … … 1289 1320 else 1290 1321 pNode->pFirstChild = pNew; 1322 pNew->pNext = pNext; 1323 if (pNext) 1324 pNext->pPrev = pNew; 1325 1291 1326 if (ppChild) 1292 1327 *ppChild = pNew; … … 1388 1423 * Check if already exists and find last node in chain. 1389 1424 */ 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) 1393 1429 { 1394 for (; ; pPrev = pPrev->pNext)1430 for (; pNext; pPrev = pNext, pNext = pNext->pNext) 1395 1431 { 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; 1400 1437 break; 1438 } 1401 1439 } 1402 1440 } … … 1414 1452 * Insert into child list. 1415 1453 */ 1416 pNew->pNext = NULL;1417 1454 pNew->pPrev = pPrev; 1418 1455 if (pPrev) … … 1420 1457 else 1421 1458 pNode->pFirstLeaf = pNew; 1459 pNew->pNext = pNext; 1460 if (pNext) 1461 pNext->pPrev = pNew; 1462 1422 1463 *ppLeaf = pNew; 1423 1464 rc = VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.