[3/3] wineps.drv: Only allocate buffers for large text strings

Daniel Horn danielrh at dropbox.com
Fri Sep 5 01:30:09 CDT 2014


-------------- next part --------------
From 4c472c156d752231c244e79d0aa0a76e36b5c5ee Mon Sep 17 00:00:00 2001
From: Daniel Reiter Horn <danielrh at dropbox.com>
Date: Fri, 5 Sep 2014 03:25:11 +0000
Subject: [PATCH 3/3] Only allocate buffers for large text strings

Right now a buffer is allocated in the inner print loop for glyph name lookup. This patch makes it so that a critical threshold must be reached before such a buffer is allocated on the heap.

This patch has been tested on hundreds of print jobs under linux ubuntu 12.04 with a wide array of commonly used text editors
---
 dlls/wineps.drv/text.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/dlls/wineps.drv/text.c b/dlls/wineps.drv/text.c
index b85784d..2eea9ca 100644
--- a/dlls/wineps.drv/text.c
+++ b/dlls/wineps.drv/text.c
@@ -211,12 +211,18 @@ static BOOL PSDRV_Text(PHYSDEV dev, INT x, INT y, UINT flags, LPCWSTR str,
 {
     PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
     LPCWSTR glyphs = str;
+    WORD *glyphsAlloc = NULL;
+    WORD glyphsBacking[65536];
     if (!count)
 	return TRUE;
 
     if(physDev->font.fontloc == Download && !(flags & ETO_GLYPH_INDEX))
     {
-        glyphs = HeapAlloc( GetProcessHeap(), 0, count * sizeof(WORD) );
+        if (count > sizeof(glyphsBacking) / sizeof(glyphsBacking[0])) {
+            glyphs = glyphsAlloc = HeapAlloc( GetProcessHeap(), 0, count * sizeof(WORD) );
+        } else {
+            glyphs = glyphsBacking;
+        }
         GetGlyphIndicesW( dev->hdc, str, count, glyphs, 0 );
     }
 
@@ -251,8 +257,6 @@ static BOOL PSDRV_Text(PHYSDEV dev, INT x, INT y, UINT flags, LPCWSTR str,
 	else
 	    PSDRV_WriteBuiltinGlyphShow(dev, str + i, 1);
     }
-    if (glyphs != str) {
-        HeapFree( GetProcessHeap(), 0, glyphs );
-    }
+    HeapFree( GetProcessHeap(), 0, glyphsAlloc );
     return TRUE;
 }
-- 
1.8.4.2



More information about the wine-patches mailing list