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

malloc/free are slow. CORE-19358
This commit is contained in:
Katayama Hirofumi MZ 2023-12-10 18:09:59 +09:00
parent 468a5492a9
commit dc2d2232f4
3 changed files with 34 additions and 24 deletions

View file

@ -13,7 +13,7 @@ void Anime_FreeInfo(PANIME pAnime)
{
if (pAnime->m_pDelayItem)
{
free(pAnime->m_pDelayItem);
QuickFree(pAnime->m_pDelayItem);
pAnime->m_pDelayItem = NULL;
}
pAnime->m_nFrameIndex = 0;
@ -101,13 +101,13 @@ BOOL Anime_LoadInfo(PANIME pAnime)
GdipImageGetFrameDimensionsCount(g_pImage, &nDimCount);
if (nDimCount)
{
GUID *dims = (GUID *)calloc(nDimCount, sizeof(GUID));
GUID *dims = (GUID *)QuickAlloc(nDimCount * sizeof(GUID), TRUE);
if (dims)
{
GdipImageGetFrameDimensionsList(g_pImage, dims, nDimCount);
GdipImageGetFrameCount(g_pImage, dims, &result);
pAnime->m_nFrameCount = result;
free(dims);
QuickFree(dims);
}
}
@ -116,7 +116,7 @@ BOOL Anime_LoadInfo(PANIME pAnime)
cbItem = result;
if (cbItem)
{
pAnime->m_pDelayItem = (PropertyItem *)malloc(cbItem);
pAnime->m_pDelayItem = (PropertyItem *)QuickAlloc(cbItem, FALSE);
GdipGetPropertyItem(g_pImage, PropertyTagFrameDelay, cbItem, pAnime->m_pDelayItem);
}
@ -125,14 +125,14 @@ BOOL Anime_LoadInfo(PANIME pAnime)
cbItem = result;
if (cbItem)
{
PropertyItem *pItem = (PropertyItem *)malloc(cbItem);
PropertyItem *pItem = (PropertyItem *)QuickAlloc(cbItem, FALSE);
if (pItem)
{
if (GdipGetPropertyItem(g_pImage, PropertyTagLoopCount, cbItem, pItem) == Ok)
{
pAnime->m_nLoopCount = *(WORD *)pItem->value;
}
free(pItem);
QuickFree(pItem);
}
}

View file

@ -243,10 +243,10 @@ static VOID pSaveImageAs(HWND hwnd)
return;
GdipGetImageEncodersSize(&num, &size);
codecInfo = malloc(size);
codecInfo = QuickAlloc(size, FALSE);
if (!codecInfo)
{
DPRINT1("malloc() failed in pSaveImageAs()\n");
DPRINT1("QuickAlloc() failed in pSaveImageAs()\n");
return;
}
@ -263,11 +263,11 @@ static VOID pSaveImageAs(HWND hwnd)
/* Add two more chars for the last terminator */
sizeRemain += (sizeof(WCHAR) * 2);
szFilterMask = malloc(sizeRemain);
szFilterMask = QuickAlloc(sizeRemain, FALSE);
if (!szFilterMask)
{
DPRINT1("cannot allocate memory for filter mask in pSaveImageAs()");
free(codecInfo);
QuickFree(codecInfo);
return;
}
@ -316,8 +316,8 @@ static VOID pSaveImageAs(HWND hwnd)
Anime_Start(&g_Anime, 0);
}
free(szFilterMask);
free(codecInfo);
QuickFree(szFilterMask);
QuickFree(codecInfo);
}
static VOID
@ -380,20 +380,20 @@ pBuildFileList(LPCWSTR szFirstFile)
PathRemoveFileSpecW(szSearchPath);
GdipGetImageDecodersSize(&num, &size);
codecInfo = malloc(size);
codecInfo = QuickAlloc(size, FALSE);
if (!codecInfo)
{
DPRINT1("malloc() failed in pLoadFileList()\n");
DPRINT1("QuickAlloc() failed in pLoadFileList()\n");
return NULL;
}
GdipGetImageDecoders(num, size, codecInfo);
root = malloc(sizeof(SHIMGVW_FILENODE));
root = QuickAlloc(sizeof(SHIMGVW_FILENODE), FALSE);
if (!root)
{
DPRINT1("malloc() failed in pLoadFileList()\n");
free(codecInfo);
DPRINT1("QuickAlloc() failed in pLoadFileList()\n");
QuickFree(codecInfo);
return NULL;
}
@ -422,18 +422,18 @@ pBuildFileList(LPCWSTR szFirstFile)
currentNode = conductor;
}
conductor->Next = malloc(sizeof(SHIMGVW_FILENODE));
conductor->Next = QuickAlloc(sizeof(SHIMGVW_FILENODE), FALSE);
// if malloc fails, make circular what we have and return it
// if QuickAlloc fails, make circular what we have and return it
if (!conductor->Next)
{
DPRINT1("malloc() failed in pLoadFileList()\n");
DPRINT1("QuickAlloc() failed in pLoadFileList()\n");
conductor->Next = root;
root->Prev = conductor;
FindClose(hFindHandle);
free(codecInfo);
QuickFree(codecInfo);
return conductor;
}
@ -459,7 +459,7 @@ pBuildFileList(LPCWSTR szFirstFile)
else
{
conductor = conductor->Prev;
free(conductor->Next);
QuickFree(conductor->Next);
}
// link the last node with the first one to make the list circular
@ -467,7 +467,7 @@ pBuildFileList(LPCWSTR szFirstFile)
root->Prev = conductor;
conductor = currentNode;
free(codecInfo);
QuickFree(codecInfo);
return conductor;
}
@ -487,7 +487,7 @@ pFreeFileList(SHIMGVW_FILENODE *root)
{
conductor = root;
root = conductor->Next;
free(conductor);
QuickFree(conductor);
}
}

View file

@ -72,3 +72,13 @@ void Anime_SetFrameIndex(PANIME pAnime, UINT nFrameIndex);
void Anime_Start(PANIME pAnime, DWORD dwDelay);
void Anime_Pause(PANIME pAnime);
BOOL Anime_OnTimer(PANIME pAnime, WPARAM wParam);
static inline LPVOID QuickAlloc(SIZE_T cbSize, BOOL bZero)
{
return HeapAlloc(GetProcessHeap(), (bZero ? HEAP_ZERO_MEMORY : 0), cbSize);
}
static inline VOID QuickFree(LPVOID ptr)
{
HeapFree(GetProcessHeap(), 0, ptr);
}