Use local buffer in RtlUpcaseUnicodeStringToCountedOemString, if appropriate

Uwe Bonnes bon at elektron.ikp.physik.tu-darmstadt.de
Sun Feb 13 12:22:23 CST 2005


Hallo,

appended patch supplies a local buffer for
RtlUpcaseUnicodeStringToCountedOemString and uses this buffer, if it is
large enough. The function is called a lot of times in our file handling
code. Without the supplied local buffer, HeapAlloc and HeapFree is called,
and for some *nst*llsh**ld application the alloc/free acounted for about 10
% of  a +relay output. Even if the saved heap allocation/ freeing may not be
worth patch (I can't judge), the cleaning up of the relay log should be
worth applying the patch( if I codes it thread safe...)

Changelog:
	wine/dlls/ntdll/rtlstr.c: RtlUpcaseUnicodeStringToCountedOemString()
	Supply a local buffer and use if large enough


-- 
Uwe Bonnes                bon at elektron.ikp.physik.tu-darmstadt.de

Institut fuer Kernphysik  Schlossgartenstrasse 9  64289 Darmstadt
--------- Tel. 06151 162516 -------- Fax. 06151 164321 ----------
Index: wine/dlls/ntdll/rtlstr.c
===================================================================
RCS file: /home/wine/wine/dlls/ntdll/rtlstr.c,v
retrieving revision 1.45
diff -6 -u -r1.45 rtlstr.c
--- wine/dlls/ntdll/rtlstr.c	19 Apr 2004 03:05:07 -0000	1.45
+++ wine/dlls/ntdll/rtlstr.c	13 Feb 2005 17:47:15 -0000
@@ -1068,14 +1068,23 @@
 NTSTATUS WINAPI RtlUpcaseUnicodeStringToCountedOemString( STRING *oem,
                                                           const UNICODE_STRING *uni,
                                                           BOOLEAN doalloc )
 {
     NTSTATUS ret;
     UNICODE_STRING upcase;
+    WCHAR tmp[MAX_PATH];
 
-    if (!(ret = RtlUpcaseUnicodeString( &upcase, uni, TRUE )))
+    if (uni->Length > MAX_PATH)
+        ret = RtlUpcaseUnicodeString( &upcase, uni, TRUE );           
+    else {
+        upcase.Buffer = tmp;
+        upcase.MaximumLength = MAX_PATH * sizeof(WCHAR);
+        ret = RtlUpcaseUnicodeString( &upcase, uni, FALSE );
+    }
+
+    if (!(ret))
     {
         DWORD len = RtlUnicodeStringToOemSize( &upcase ) - 1;
         oem->Length = len;
         if (doalloc)
         {
             oem->MaximumLength = len;
@@ -1090,13 +1099,14 @@
             ret = STATUS_BUFFER_OVERFLOW;
             oem->Length = oem->MaximumLength;
             if (!oem->MaximumLength) goto done;
         }
         RtlUnicodeToOemN( oem->Buffer, oem->Length, NULL, upcase.Buffer, upcase.Length );
     done:
-        RtlFreeUnicodeString( &upcase );
+        if (upcase.Buffer != tmp)
+	    RtlFreeUnicodeString( &upcase );
     }
     return ret;
 }
 
 
 /**************************************************************************



More information about the wine-patches mailing list