Reactos

[SHIMGVW] Use HeapAlloc/HeapFree instead of malloc/calloc/free

malloc/free are slow. CORE-19358

+34 -24
+6 -6
dll/win32/shimgvw/anime.c
··· 13 13 { 14 14 if (pAnime->m_pDelayItem) 15 15 { 16 - free(pAnime->m_pDelayItem); 16 + QuickFree(pAnime->m_pDelayItem); 17 17 pAnime->m_pDelayItem = NULL; 18 18 } 19 19 pAnime->m_nFrameIndex = 0; ··· 101 101 GdipImageGetFrameDimensionsCount(g_pImage, &nDimCount); 102 102 if (nDimCount) 103 103 { 104 - GUID *dims = (GUID *)calloc(nDimCount, sizeof(GUID)); 104 + GUID *dims = (GUID *)QuickAlloc(nDimCount * sizeof(GUID), TRUE); 105 105 if (dims) 106 106 { 107 107 GdipImageGetFrameDimensionsList(g_pImage, dims, nDimCount); 108 108 GdipImageGetFrameCount(g_pImage, dims, &result); 109 109 pAnime->m_nFrameCount = result; 110 - free(dims); 110 + QuickFree(dims); 111 111 } 112 112 } 113 113 ··· 116 116 cbItem = result; 117 117 if (cbItem) 118 118 { 119 - pAnime->m_pDelayItem = (PropertyItem *)malloc(cbItem); 119 + pAnime->m_pDelayItem = (PropertyItem *)QuickAlloc(cbItem, FALSE); 120 120 GdipGetPropertyItem(g_pImage, PropertyTagFrameDelay, cbItem, pAnime->m_pDelayItem); 121 121 } 122 122 ··· 125 125 cbItem = result; 126 126 if (cbItem) 127 127 { 128 - PropertyItem *pItem = (PropertyItem *)malloc(cbItem); 128 + PropertyItem *pItem = (PropertyItem *)QuickAlloc(cbItem, FALSE); 129 129 if (pItem) 130 130 { 131 131 if (GdipGetPropertyItem(g_pImage, PropertyTagLoopCount, cbItem, pItem) == Ok) 132 132 { 133 133 pAnime->m_nLoopCount = *(WORD *)pItem->value; 134 134 } 135 - free(pItem); 135 + QuickFree(pItem); 136 136 } 137 137 } 138 138
+18 -18
dll/win32/shimgvw/shimgvw.c
··· 243 243 return; 244 244 245 245 GdipGetImageEncodersSize(&num, &size); 246 - codecInfo = malloc(size); 246 + codecInfo = QuickAlloc(size, FALSE); 247 247 if (!codecInfo) 248 248 { 249 - DPRINT1("malloc() failed in pSaveImageAs()\n"); 249 + DPRINT1("QuickAlloc() failed in pSaveImageAs()\n"); 250 250 return; 251 251 } 252 252 ··· 263 263 /* Add two more chars for the last terminator */ 264 264 sizeRemain += (sizeof(WCHAR) * 2); 265 265 266 - szFilterMask = malloc(sizeRemain); 266 + szFilterMask = QuickAlloc(sizeRemain, FALSE); 267 267 if (!szFilterMask) 268 268 { 269 269 DPRINT1("cannot allocate memory for filter mask in pSaveImageAs()"); 270 - free(codecInfo); 270 + QuickFree(codecInfo); 271 271 return; 272 272 } 273 273 ··· 316 316 Anime_Start(&g_Anime, 0); 317 317 } 318 318 319 - free(szFilterMask); 320 - free(codecInfo); 319 + QuickFree(szFilterMask); 320 + QuickFree(codecInfo); 321 321 } 322 322 323 323 static VOID ··· 380 380 PathRemoveFileSpecW(szSearchPath); 381 381 382 382 GdipGetImageDecodersSize(&num, &size); 383 - codecInfo = malloc(size); 383 + codecInfo = QuickAlloc(size, FALSE); 384 384 if (!codecInfo) 385 385 { 386 - DPRINT1("malloc() failed in pLoadFileList()\n"); 386 + DPRINT1("QuickAlloc() failed in pLoadFileList()\n"); 387 387 return NULL; 388 388 } 389 389 390 390 GdipGetImageDecoders(num, size, codecInfo); 391 391 392 - root = malloc(sizeof(SHIMGVW_FILENODE)); 392 + root = QuickAlloc(sizeof(SHIMGVW_FILENODE), FALSE); 393 393 if (!root) 394 394 { 395 - DPRINT1("malloc() failed in pLoadFileList()\n"); 396 - free(codecInfo); 395 + DPRINT1("QuickAlloc() failed in pLoadFileList()\n"); 396 + QuickFree(codecInfo); 397 397 return NULL; 398 398 } 399 399 ··· 422 422 currentNode = conductor; 423 423 } 424 424 425 - conductor->Next = malloc(sizeof(SHIMGVW_FILENODE)); 425 + conductor->Next = QuickAlloc(sizeof(SHIMGVW_FILENODE), FALSE); 426 426 427 - // if malloc fails, make circular what we have and return it 427 + // if QuickAlloc fails, make circular what we have and return it 428 428 if (!conductor->Next) 429 429 { 430 - DPRINT1("malloc() failed in pLoadFileList()\n"); 430 + DPRINT1("QuickAlloc() failed in pLoadFileList()\n"); 431 431 432 432 conductor->Next = root; 433 433 root->Prev = conductor; 434 434 435 435 FindClose(hFindHandle); 436 - free(codecInfo); 436 + QuickFree(codecInfo); 437 437 return conductor; 438 438 } 439 439 ··· 459 459 else 460 460 { 461 461 conductor = conductor->Prev; 462 - free(conductor->Next); 462 + QuickFree(conductor->Next); 463 463 } 464 464 465 465 // link the last node with the first one to make the list circular ··· 467 467 root->Prev = conductor; 468 468 conductor = currentNode; 469 469 470 - free(codecInfo); 470 + QuickFree(codecInfo); 471 471 472 472 return conductor; 473 473 } ··· 487 487 { 488 488 conductor = root; 489 489 root = conductor->Next; 490 - free(conductor); 490 + QuickFree(conductor); 491 491 } 492 492 } 493 493
+10
dll/win32/shimgvw/shimgvw.h
··· 72 72 void Anime_Start(PANIME pAnime, DWORD dwDelay); 73 73 void Anime_Pause(PANIME pAnime); 74 74 BOOL Anime_OnTimer(PANIME pAnime, WPARAM wParam); 75 + 76 + static inline LPVOID QuickAlloc(SIZE_T cbSize, BOOL bZero) 77 + { 78 + return HeapAlloc(GetProcessHeap(), (bZero ? HEAP_ZERO_MEMORY : 0), cbSize); 79 + } 80 + 81 + static inline VOID QuickFree(LPVOID ptr) 82 + { 83 + HeapFree(GetProcessHeap(), 0, ptr); 84 + }