Commit 038ede84 authored by Alexandre Julliard's avatar Alexandre Julliard

Avoid heap reallocation each time a metarecord is written in memory

(based on a patch by Warren Baird).
parent 81c31701
...@@ -378,7 +378,7 @@ HMETAFILE WINAPI CloseMetaFile( ...@@ -378,7 +378,7 @@ HMETAFILE WINAPI CloseMetaFile(
*/ */
BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen) BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen)
{ {
DWORD len; DWORD len, size;
METAHEADER *mh; METAHEADER *mh;
METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev; METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
...@@ -386,9 +386,17 @@ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen) ...@@ -386,9 +386,17 @@ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen)
{ {
case METAFILE_MEMORY: case METAFILE_MEMORY:
len = physDev->mh->mtSize * 2 + rlen; len = physDev->mh->mtSize * 2 + rlen;
mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, len ); /* reallocate memory if needed */
if (!mh) return FALSE; size = HeapSize( GetProcessHeap(), 0, physDev->mh );
physDev->mh = 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); memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen);
break; break;
case METAFILE_DISK: case METAFILE_DISK:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment