Commit 8e752cd4 authored by tkent@chromium.org's avatar tkent@chromium.org

Improve <textarea> validation performance.

HTMLTextAreaElement::value() is a costly operation, and we can avoid it
if a <textarea> has neither 'required' attribute nor 'maxlength' attribute.

This CL improves PerformanceTests/DOM/textarea-dom.html and
textarea-edit.html by a few percent.

BUG=

Review URL: https://codereview.chromium.org/543403003

git-svn-id: svn://svn.chromium.org/blink/trunk@181785 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent d2bdad9a
...@@ -490,15 +490,22 @@ String HTMLTextAreaElement::validationMessage() const ...@@ -490,15 +490,22 @@ String HTMLTextAreaElement::validationMessage() const
bool HTMLTextAreaElement::valueMissing() const bool HTMLTextAreaElement::valueMissing() const
{ {
return willValidate() && valueMissing(value()); // We should not call value() for performance.
return willValidate() && valueMissing(0);
}
bool HTMLTextAreaElement::valueMissing(const String* value) const
{
return isRequiredFormControl() && !isDisabledOrReadOnly() && (value ? *value : this->value()).isEmpty();
} }
bool HTMLTextAreaElement::tooLong() const bool HTMLTextAreaElement::tooLong() const
{ {
return willValidate() && tooLong(value(), CheckDirtyFlag); // We should not call value() for performance.
return willValidate() && tooLong(0, CheckDirtyFlag);
} }
bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const bool HTMLTextAreaElement::tooLong(const String* value, NeedsToCheckDirtyFlag check) const
{ {
// Return false for the default value or value set by script even if it is // Return false for the default value or value set by script even if it is
// longer than maxLength. // longer than maxLength.
...@@ -508,12 +515,12 @@ bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag che ...@@ -508,12 +515,12 @@ bool HTMLTextAreaElement::tooLong(const String& value, NeedsToCheckDirtyFlag che
int max = maxLength(); int max = maxLength();
if (max < 0) if (max < 0)
return false; return false;
return computeLengthForSubmission(value) > static_cast<unsigned>(max); return computeLengthForSubmission(value ? *value : this->value()) > static_cast<unsigned>(max);
} }
bool HTMLTextAreaElement::isValidValue(const String& candidate) const bool HTMLTextAreaElement::isValidValue(const String& candidate) const
{ {
return !valueMissing(candidate) && !tooLong(candidate, IgnoreDirtyFlag); return !valueMissing(&candidate) && !tooLong(&candidate, IgnoreDirtyFlag);
} }
void HTMLTextAreaElement::accessKeyAction(bool) void HTMLTextAreaElement::accessKeyAction(bool)
......
...@@ -121,8 +121,9 @@ private: ...@@ -121,8 +121,9 @@ private:
virtual bool matchesReadOnlyPseudoClass() const OVERRIDE; virtual bool matchesReadOnlyPseudoClass() const OVERRIDE;
virtual bool matchesReadWritePseudoClass() const OVERRIDE; virtual bool matchesReadWritePseudoClass() const OVERRIDE;
bool valueMissing(const String& value) const { return isRequiredFormControl() && !isDisabledOrReadOnly() && value.isEmpty(); } // If the String* argument is 0, apply this->value().
bool tooLong(const String&, NeedsToCheckDirtyFlag) const; bool valueMissing(const String*) const;
bool tooLong(const String*, NeedsToCheckDirtyFlag) const;
int m_rows; int m_rows;
int m_cols; int m_cols;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment