oleaut32: Avoid unnecessary allocations in TLB_MultiByteToBSTR and SLTG_ReadString.

This commit is contained in:
Rob Shearman 2008-08-14 18:50:49 +01:00 committed by Alexandre Julliard
parent ef5a5a4490
commit 2fab79955f
1 changed files with 6 additions and 10 deletions

View File

@ -2753,14 +2753,12 @@ static ITypeLib2* ITypeLib2_Constructor_MSFT(LPVOID pLib, DWORD dwTLBLength)
static BSTR TLB_MultiByteToBSTR(const char *ptr) static BSTR TLB_MultiByteToBSTR(const char *ptr)
{ {
DWORD len; DWORD len;
WCHAR *nameW;
BSTR ret; BSTR ret;
len = MultiByteToWideChar(CP_ACP, 0, ptr, -1, NULL, 0); len = MultiByteToWideChar(CP_ACP, 0, ptr, -1, NULL, 0);
nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); ret = SysAllocStringLen(NULL, len - 1);
MultiByteToWideChar(CP_ACP, 0, ptr, -1, nameW, len); if (!ret) return ret;
ret = SysAllocString(nameW); MultiByteToWideChar(CP_ACP, 0, ptr, -1, ret, len);
HeapFree(GetProcessHeap(), 0, nameW);
return ret; return ret;
} }
@ -2790,16 +2788,14 @@ static WORD SLTG_ReadString(const char *ptr, BSTR *pBstr)
{ {
WORD bytelen; WORD bytelen;
DWORD len; DWORD len;
WCHAR *nameW;
*pBstr = NULL; *pBstr = NULL;
bytelen = *(const WORD*)ptr; bytelen = *(const WORD*)ptr;
if(bytelen == 0xffff) return 2; if(bytelen == 0xffff) return 2;
len = MultiByteToWideChar(CP_ACP, 0, ptr + 2, bytelen, NULL, 0); len = MultiByteToWideChar(CP_ACP, 0, ptr + 2, bytelen, NULL, 0);
nameW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); *pBstr = SysAllocStringLen(NULL, len - 1);
len = MultiByteToWideChar(CP_ACP, 0, ptr + 2, bytelen, nameW, len); if (*pBstr)
*pBstr = SysAllocStringLen(nameW, len); len = MultiByteToWideChar(CP_ACP, 0, ptr + 2, bytelen, *pBstr, len);
HeapFree(GetProcessHeap(), 0, nameW);
return bytelen + 2; return bytelen + 2;
} }