There's no reason to allocate and then parse the entire string just to see if its length is zero.
Signed-off-by: Gabriel Ivăncescu gabrielopcode@gmail.com ---
This also keeps it consistent with SB_GetIdealSize's style and simplifies the code.
dlls/comctl32/button.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-)
diff --git a/dlls/comctl32/button.c b/dlls/comctl32/button.c index 213ab29..18b7430 100644 --- a/dlls/comctl32/button.c +++ b/dlls/comctl32/button.c @@ -1257,20 +1257,16 @@ static BOOL GB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size) static BOOL CB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size) { LONG style = GetWindowLongW(infoPtr->hwnd, GWL_STYLE); - WCHAR *text = get_button_text(infoPtr); HDC hdc; HFONT hfont; SIZE labelSize; INT textOffset; - INT textLength = 0; double scaleX; double scaleY; LONG checkboxWidth, checkboxHeight; LONG maxWidth = 0;
- if (text) textLength = lstrlenW(text); - heap_free(text); - if (textLength == 0) + if (SendMessageW(infoPtr->hwnd, WM_GETTEXTLENGTH, 0, 0) == 0) { BUTTON_GetClientRectSize(infoPtr, size); return TRUE; @@ -1306,26 +1302,18 @@ static BOOL CB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size)
static BOOL PB_GetIdealSize(BUTTON_INFO *infoPtr, SIZE *size) { - WCHAR *text = get_button_text(infoPtr); SIZE labelSize; - INT textLength = 0; - - if (text) textLength = lstrlenW(text);
- if (textLength == 0) - { + if (SendMessageW(infoPtr->hwnd, WM_GETTEXTLENGTH, 0, 0) == 0) BUTTON_GetClientRectSize(infoPtr, size); - heap_free(text); - return TRUE; - } - heap_free(text); - - /* Ideal size include text size even if image only flags(BS_ICON, BS_BITMAP) are specified */ - BUTTON_GetLabelIdealSize(infoPtr, size->cx, &labelSize); - - size->cx = labelSize.cx; - size->cy = labelSize.cy; + else + { + /* Ideal size include text size even if image only flags(BS_ICON, BS_BITMAP) are specified */ + BUTTON_GetLabelIdealSize(infoPtr, size->cx, &labelSize);
+ size->cx = labelSize.cx; + size->cy = labelSize.cy; + } return TRUE; }