https://git.reactos.org/?p=reactos.git;a=commitdiff;h=dc2d2232f45956cf496b8…
commit dc2d2232f45956cf496b8f80ecb9a4c19d77f7f2
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sun Dec 10 18:09:59 2023 +0900
Commit: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
CommitDate: Sun Dec 10 18:09:59 2023 +0900
[SHIMGVW] Use HeapAlloc/HeapFree instead of malloc/calloc/free
malloc/free are slow. CORE-19358
---
dll/win32/shimgvw/anime.c | 12 ++++++------
dll/win32/shimgvw/shimgvw.c | 36 ++++++++++++++++++------------------
dll/win32/shimgvw/shimgvw.h | 10 ++++++++++
3 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/dll/win32/shimgvw/anime.c b/dll/win32/shimgvw/anime.c
index 6348c43b903..3b247cfac24 100644
--- a/dll/win32/shimgvw/anime.c
+++ b/dll/win32/shimgvw/anime.c
@@ -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);
}
}
diff --git a/dll/win32/shimgvw/shimgvw.c b/dll/win32/shimgvw/shimgvw.c
index 32f944c55a5..82775a85d55 100644
--- a/dll/win32/shimgvw/shimgvw.c
+++ b/dll/win32/shimgvw/shimgvw.c
@@ -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);
}
}
diff --git a/dll/win32/shimgvw/shimgvw.h b/dll/win32/shimgvw/shimgvw.h
index 99a159a4cd1..a9a7b7b8daa 100644
--- a/dll/win32/shimgvw/shimgvw.h
+++ b/dll/win32/shimgvw/shimgvw.h
@@ -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);
+}