Changeset 59972 in vbox
- Timestamp:
- Mar 9, 2016 8:06:41 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/mangling.h
r59754 r59972 1730 1730 # define RTSortApvShell RT_MANGLER(RTSortApvShell) 1731 1731 # define RTSortIsSorted RT_MANGLER(RTSortIsSorted) 1732 # define RTSortShell RT_MANGLER(RTSortShell) 1732 1733 # define RTSpinlockAcquire RT_MANGLER(RTSpinlockAcquire) 1733 1734 # define RTSpinlockAcquireNoInts RT_MANGLER(RTSpinlockAcquireNoInts) -
trunk/src/VBox/Runtime/common/dbg/dbgmodcodeview.cpp
r59232 r59972 57 57 #include <iprt/param.h> 58 58 #include <iprt/path.h> 59 #include <iprt/sort.h> 59 60 #include <iprt/string.h> 60 61 #include <iprt/strcache.h> … … 69 70 * Structures and Typedefs * 70 71 *********************************************************************************************************************************/ 71 /**72 * Directory sorting order.73 */74 typedef enum RTCVDIRORDER75 {76 RTCVDIRORDER_INVALID = 0,77 /** Ordered by module. */78 RTCVDIRORDER_BY_MOD,79 /** Ordered by module, but 0 modules at the end. */80 RTCVDIRORDER_BY_MOD_0,81 /** Ordered by section, with global modules at the end. */82 RTCVDIRORDER_BY_SST_MOD83 } RTCVDIRORDER;84 85 86 72 /** 87 73 * File type. … … 123 109 /** The offset of the subsection directory (relative to offBase). */ 124 110 uint32_t offDir; 125 /** The directory order. */126 RTCVDIRORDER enmDirOrder;127 111 /** @} */ 128 112 … … 1375 1359 1376 1360 /** 1361 * @callback_method_impl{PFNRTSORTCMP, 1362 * Used by rtDbgModCvLoadDirectory to sort the directory.} 1363 */ 1364 static DECLCALLBACK(int) rtDbgModCvDirEntCmp(void const *pvElement1, void const *pvElement2, void *pvUser) 1365 { 1366 PRTCVDIRENT32 pEntry1 = (PRTCVDIRENT32)pvElement1; 1367 PRTCVDIRENT32 pEntry2 = (PRTCVDIRENT32)pvElement2; 1368 if (pEntry1->iMod < pEntry2->iMod) 1369 return -1; 1370 if (pEntry1->iMod > pEntry2->iMod) 1371 return 1; 1372 if (pEntry1->uSubSectType < pEntry2->uSubSectType) 1373 return -1; 1374 if (pEntry1->uSubSectType > pEntry2->uSubSectType) 1375 return 1; 1376 return 0; 1377 } 1378 1379 1380 /** 1377 1381 * Loads the directory into memory (RTDBGMODCV::paDirEnts and 1378 1382 * RTDBGMODCV::cDirEnts). … … 1485 1489 if (RT_SUCCESS(rc)) 1486 1490 { 1491 uint32_t const cbDbgInfo = pThis->cbDbgInfo; 1492 uint32_t const cDirEnts = pThis->cDirEnts; 1493 1487 1494 /* 1488 * Basic info validation and determining the directory ordering. 1495 * Just sort the directory in a way we like, no need to make 1496 * complicated demands on the linker output. 1489 1497 */ 1490 bool fWatcom = 0; 1498 RTSortShell(pThis->paDirEnts, cDirEnts, sizeof(pThis->paDirEnts[0]), rtDbgModCvDirEntCmp, NULL); 1499 1500 /* 1501 * Basic info validation. 1502 */ 1491 1503 uint16_t cGlobalMods = 0; 1492 1504 uint16_t cNormalMods = 0; 1493 1505 uint16_t iModLast = 0; 1494 uint32_t const cbDbgInfo = pThis->cbDbgInfo;1495 uint32_t const cDirEnts = pThis->cDirEnts;1496 1506 Log2(("RTDbgModCv: %u (%#x) directory entries:\n", cDirEnts, cDirEnts)); 1497 1507 for (uint32_t i = 0; i < cDirEnts; i++) … … 1537 1547 iModLast = pDirEnt->iMod; 1538 1548 } 1539 else if (pDirEnt->iMod < iModLast)1540 fWatcom = true;1541 1549 cNormalMods++; 1542 1550 } … … 1549 1557 if (RT_SUCCESS(rc)) 1550 1558 { 1551 if (fWatcom) 1552 pThis->enmDirOrder = RTCVDIRORDER_BY_SST_MOD; 1553 else if (pThis->paDirEnts[0].iMod == 0) 1554 pThis->enmDirOrder = RTCVDIRORDER_BY_MOD_0; 1555 else 1556 pThis->enmDirOrder = RTCVDIRORDER_BY_MOD; 1557 Log(("CV dir stats: %u total, %u normal, %u special, iModLast=%#x (%u), enmDirOrder=%d\n", 1558 cDirEnts, cNormalMods, cGlobalMods, iModLast, iModLast, pThis->enmDirOrder)); 1559 1560 1559 Log(("CV dir stats: %u total, %u normal, %u special, iModLast=%#x (%u)\n", 1560 cDirEnts, cNormalMods, cGlobalMods, iModLast, iModLast)); 1561 1562 #if 0 /* skip this stuff */ 1561 1563 /* 1562 1564 * Validate the directory ordering. 1563 1565 */ 1564 1566 uint16_t i = 0; 1565 1566 /* Old style with special modules up front. */1567 if (pThis->enmDirOrder == RTCVDIRORDER_BY_MOD_0)1568 while (i < cGlobalMods)1569 {1570 if (pThis->paDirEnts[i].iMod != 0)1571 {1572 Log(("CV directory entry #%u: Expected iMod=%x instead of %x\n", i, 0, pThis->paDirEnts[i].iMod));1573 rc = VERR_CV_BAD_FORMAT;1574 }1575 i++;1576 }1577 1567 1578 1568 /* Normal modules. */ … … 1648 1638 i++; 1649 1639 } 1650 } 1651 1640 #endif 1641 } 1652 1642 } 1653 1643 -
trunk/src/VBox/Runtime/common/sort/shellsort.cpp
r57358 r59972 32 32 #include <iprt/sort.h> 33 33 34 #include <iprt/alloca.h> 35 #include <iprt/assert.h> 36 #include <iprt/string.h> 37 38 39 40 RTDECL(void) RTSortShell(void *pvArray, size_t cElements, size_t cbElement, PFNRTSORTCMP pfnCmp, void *pvUser) 41 { 42 Assert(cbElement <= 32); 43 44 /* Anything worth sorting? */ 45 if (cElements < 2) 46 return; 47 48 uint8_t *pbArray = (uint8_t *)pvArray; 49 void *pvTmp = alloca(cbElement); 50 size_t cGap = (cElements + 1) / 2; 51 while (cGap > 0) 52 { 53 size_t i; 54 for (i = cGap; i < cElements; i++) 55 { 56 memcpy(pvTmp, &pbArray[i * cbElement], cbElement); 57 size_t j = i; 58 while ( j >= cGap 59 && pfnCmp(&pbArray[(j - cGap) * cbElement], pvTmp, pvUser) > 0) 60 { 61 memmove(&pbArray[j * cbElement], &pbArray[(j - cGap) * cbElement], cbElement); 62 j -= cGap; 63 } 64 memcpy(&pbArray[j * cbElement], pvTmp, cbElement); 65 } 66 67 /* This does not generate the most optimal gap sequence, but it has the 68 advantage of being simple and avoid floating point. */ 69 cGap /= 2; 70 } 71 } 34 72 35 73 -
trunk/src/VBox/Runtime/testcase/tstRTSort.cpp
r57358 r59972 35 35 #include <iprt/string.h> 36 36 #include <iprt/test.h> 37 #include <iprt/time.h> 37 38 38 39 … … 94 95 95 96 97 static DECLCALLBACK(int) testCompare(void const *pvElement1, void const *pvElement2, void *pvUser) 98 { 99 return memcmp(pvElement1, pvElement2, (size_t)pvUser); 100 } 101 102 static void testSorter(RTTEST hTest, FNRTSORT pfnSorter, const char *pszName) 103 { 104 RTTestISub(pszName); 105 106 /* Use pseudo random config and data. */ 107 RTRAND hRand; 108 RTTESTI_CHECK_RC_OK_RETV(RTRandAdvCreateParkMiller(&hRand)); 109 RTTIMESPEC Now; 110 uint64_t uSeed = RTTimeSpecGetSeconds(RTTimeNow(&Now)); 111 RTTestIPrintf(RTTESTLVL_ALWAYS, "Seed %#RX64\n", uSeed); 112 RTRandAdvSeed(hRand, uSeed); 113 114 for (uint32_t cArrays = 0; cArrays < 512; cArrays++) 115 { 116 /* Create a random array with random data bytes. */ 117 uint32_t const cElements = RTRandAdvU32Ex(hRand, 2, 8192); 118 uint32_t const cbElement = RTRandAdvU32Ex(hRand, 1, 32); 119 uint8_t *pbArray; 120 RTTESTI_CHECK_RC_OK_RETV(RTTestGuardedAlloc(hTest, cElements * cbElement, 1 /*cbAlign*/, 121 RT_BOOL(RTRandAdvU32Ex(hRand, 0, 1)) /*fHead*/, (void **)&pbArray)); 122 RTTESTI_CHECK_RETV(pbArray); 123 RTRandAdvBytes(hRand, pbArray, cElements * cbElement); 124 125 /* sort it */ 126 pfnSorter(pbArray, cElements, cbElement, testCompare, (void *)cbElement); 127 128 /* verify it */ 129 if (!RTSortIsSorted(pbArray, cElements, cbElement, testCompare, (void *)cbElement)) 130 RTTestIFailed("failed sorting %u elements of %u size", cElements, cbElement); 131 132 RTTestGuardedFree(hTest, pbArray); 133 } 134 } 135 136 96 137 int main() 97 138 { … … 105 146 * Test the different algorithms. 106 147 */ 148 testSorter(hTest, RTSortShell, "RTSortShell - shell sort, variable sized element array"); 107 149 testApvSorter(RTSortApvShell, "RTSortApvShell - shell sort, pointer array"); 108 150
Note:
See TracChangeset
for help on using the changeset viewer.