From 038ede847452fb0deff2e7609a3743d0322acfde Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 3 Sep 2003 00:18:33 +0000 Subject: [PATCH] Avoid heap reallocation each time a metarecord is written in memory (based on a patch by Warren Baird). --- dlls/gdi/mfdrv/init.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dlls/gdi/mfdrv/init.c b/dlls/gdi/mfdrv/init.c index e20a16db2a3..cf3eb6896c8 100644 --- a/dlls/gdi/mfdrv/init.c +++ b/dlls/gdi/mfdrv/init.c @@ -378,7 +378,7 @@ HMETAFILE WINAPI CloseMetaFile( */ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen) { - DWORD len; + DWORD len, size; METAHEADER *mh; METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev; @@ -386,9 +386,17 @@ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen) { case METAFILE_MEMORY: len = physDev->mh->mtSize * 2 + rlen; - mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, len ); - if (!mh) return FALSE; - physDev->mh = mh; + /* reallocate memory if needed */ + size = HeapSize( GetProcessHeap(), 0, physDev->mh ); + if (len > size) + { + /*expand size*/ + size += size / 2 + rlen; + mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, size); + if (!mh) return FALSE; + physDev->mh = mh; + TRACE("Reallocated metafile: new size is %ld\n",size); + } memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen); break; case METAFILE_DISK: -- 2.11.4.GIT