[ros-dev] [ros-diffs] [gadamopoulos] 74552: [UXTHEME] -ThemeDrawCaptionText: Try to avoid a heap allocation when getting the window caption.
Thomas Faber
thomas.faber at reactos.org
Tue May 16 08:10:53 UTC 2017
Hi,
comments inline.
On 2017-05-15 18:05, gadamopoulos at svn.reactos.org wrote:
> --- trunk/reactos/dll/win32/uxtheme/nonclient.c [iso-8859-1] (original)
> +++ trunk/reactos/dll/win32/uxtheme/nonclient.c [iso-8859-1] Mon May 15 16:05:14 2017
> @@ -100,16 +100,7 @@
> return hIcon;
> }
>
> -WCHAR *UserGetWindowCaption(HWND hwnd)
> -{
> - INT len = 512;
> - WCHAR *text;
> - text = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
> - if (text) InternalGetWindowText(hwnd, text, len);
> - return text;
> -}
> -
> -HRESULT WINAPI ThemeDrawCaptionText(PDRAW_CONTEXT pcontext, RECT* pRect, int iPartId, int iStateId, LPCWSTR pszText)
> +HRESULT WINAPI ThemeDrawCaptionText(PDRAW_CONTEXT pcontext, RECT* pRect, int iPartId, int iStateId)
> {
> HRESULT hr;
> HFONT hFont = NULL;
> @@ -117,6 +108,25 @@
> LOGFONTW logfont;
> COLORREF textColor;
> COLORREF oldTextColor;
> +
> + WCHAR buffer[50];
> + WCHAR *pszText = buffer;
> + INT len;
> +
> + len = InternalGetWindowText(pcontext->hWnd, NULL, 0);
> + if (!len)
> + return S_OK;
> +
> + len++; /* From now on this is the size of the buffer so include the null */
> +
> + if (len > 50)
_countof(buffer), or ARRAYSIZE, or whatever people use these days.
> + {
> + pszText = (WCHAR*)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
Unnecessary cast.
> + if (!pszText)
> + return E_FAIL;
Ewwww. Worst error code.
Thanks.
-Thomas
More information about the Ros-dev
mailing list