Bug 138515

Summary: Speed up HTMLInputElement::isEmptyValue()
Product: WebKit Reporter: Chris Dumez <cdumez>
Component: DOMAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: kling, rniwa
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 138538    
Attachments:
Description Flags
Patch none

Description Chris Dumez 2014-11-07 13:52:57 PST
HTMLInputElement::isEmptyValue() currently calls HTMLTextFormControlElement::innerTextValue() which causes a full subtree traversal to construct a string representation of that subtree using a StringBuilder. In the case of HTMLInputElement::isEmptyValue(), we shouldn't have to do all this: We don't need to construct a String and we can return false as soon as we find a non-empty descendant.
Comment 1 Chris Dumez 2014-11-07 15:11:59 PST
Created attachment 241212 [details]
Patch
Comment 2 Geoffrey Garen 2014-11-07 16:47:08 PST
Comment on attachment 241212 [details]
Patch

r=me
Comment 3 Chris Dumez 2014-11-08 10:07:32 PST
Comment on attachment 241212 [details]
Patch

Clearing flags on attachment: 241212

Committed r175778: <http://trac.webkit.org/changeset/175778>
Comment 4 Chris Dumez 2014-11-08 10:07:40 PST
All reviewed patches have been landed.  Closing bug.
Comment 5 Darin Adler 2014-11-08 13:51:45 PST
Comment on attachment 241212 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=241212&action=review

> Source/WebCore/html/HTMLInputElement.cpp:1684
> +    if (!isTextField())
> +        return true;

I suggest putting this code into a virtual InputType::isEmptyValue instead of using the virtual InputType::isTextField to do a boolean check and putting the algorithm here.

> Source/WebCore/html/HTMLInputElement.cpp:1691
> +        if (text->length())
> +            return false;

There’s no whitespace collapsing rule we have to consider here?
Comment 6 Chris Dumez 2014-11-08 17:03:49 PST
Comment on attachment 241212 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=241212&action=review

>> Source/WebCore/html/HTMLInputElement.cpp:1684
>> +        return true;
> 
> I suggest putting this code into a virtual InputType::isEmptyValue instead of using the virtual InputType::isTextField to do a boolean check and putting the algorithm here.

Sounds good.

>> Source/WebCore/html/HTMLInputElement.cpp:1691
>> +            return false;
> 
> There’s no whitespace collapsing rule we have to consider here?

I did not change behavior. It was previously calling innerTextValue().isEmpty() which returns true only of the actual empty string. This function is used to determine if the placeholder should be visible or not. I would expect the placeholder to not be visible if the input contains white spaces (and as I said, this was WebKit's behavior already).