Diff
Modified: trunk/Source/WebCore/ChangeLog (208576 => 208577)
--- trunk/Source/WebCore/ChangeLog 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/ChangeLog 2016-11-11 04:32:41 UTC (rev 208577)
@@ -1,3 +1,33 @@
+2016-11-10 Chris Dumez <[email protected]>
+
+ Speed up HTMLInputElement validation
+ https://bugs.webkit.org/show_bug.cgi?id=164603
+
+ Reviewed by Ryosuke Niwa.
+
+ Speed up HTMLInputElement validation by doing 1 virtual function call
+ instead of 9 and calling HTMLInputElement::value() only once per
+ validation instead of 9 times. Calling value() is expensive because
+ of sanitization.
+
+ No new tests, no Web-exposed behavior change.
+
+ * html/BaseCheckableInputType.cpp:
+ (WebCore::BaseCheckableInputType::fallbackValue):
+ * html/FormAssociatedElement.cpp:
+ (WebCore::FormAssociatedElement::isValid):
+ * html/FormAssociatedElement.h:
+ * html/HTMLFormControlElement.cpp:
+ (WebCore::HTMLFormControlElement::isValidFormControlElement):
+ (WebCore::HTMLFormControlElement::updateValidity):
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::isValid):
+ (WebCore::HTMLInputElement::value):
+ * html/HTMLInputElement.h:
+ * html/TextFieldInputType.cpp:
+ (WebCore::limitLength):
+ * html/ValidityState.idl:
+
2016-11-10 John Wilander <[email protected]>
Add link information to data transfer pasteboard for drag and drop links
Modified: trunk/Source/WebCore/html/BaseCheckableInputType.cpp (208576 => 208577)
--- trunk/Source/WebCore/html/BaseCheckableInputType.cpp 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/html/BaseCheckableInputType.cpp 2016-11-11 04:32:41 UTC (rev 208577)
@@ -93,7 +93,8 @@
String BaseCheckableInputType::fallbackValue() const
{
- return ASCIILiteral("on");
+ static NeverDestroyed<const AtomicString> on("on", AtomicString::ConstructFromLiteral);
+ return on.get();
}
bool BaseCheckableInputType::storesValueSeparateFromAttribute()
Modified: trunk/Source/WebCore/html/FormAssociatedElement.cpp (208576 => 208577)
--- trunk/Source/WebCore/html/FormAssociatedElement.cpp 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/html/FormAssociatedElement.cpp 2016-11-11 04:32:41 UTC (rev 208577)
@@ -237,7 +237,7 @@
return false;
}
-bool FormAssociatedElement::valid() const
+bool FormAssociatedElement::isValid() const
{
bool someError = typeMismatch() || stepMismatch() || rangeUnderflow() || rangeOverflow()
|| tooShort() || tooLong() || patternMismatch() || valueMissing() || hasBadInput() || customError();
Modified: trunk/Source/WebCore/html/FormAssociatedElement.h (208576 => 208577)
--- trunk/Source/WebCore/html/FormAssociatedElement.h 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/html/FormAssociatedElement.h 2016-11-11 04:32:41 UTC (rev 208577)
@@ -82,7 +82,7 @@
virtual bool typeMismatch() const;
virtual bool valueMissing() const;
virtual String validationMessage() const;
- bool valid() const;
+ virtual bool isValid() const;
virtual void setCustomValidity(const String&);
void formAttributeTargetChanged();
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (208576 => 208577)
--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2016-11-11 04:32:41 UTC (rev 208577)
@@ -526,7 +526,7 @@
{
// If the following assertion fails, updateValidity() is not called
// correctly when something which changes validity is updated.
- ASSERT(m_isValid == valid());
+ ASSERT(m_isValid == isValid());
return m_isValid;
}
@@ -551,7 +551,7 @@
bool willValidate = this->willValidate();
bool wasValid = m_isValid;
- m_isValid = valid();
+ m_isValid = isValid();
if (willValidate && m_isValid != wasValid) {
// Update style for pseudo classes such as :valid :invalid.
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (208576 => 208577)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2016-11-11 04:32:41 UTC (rev 208577)
@@ -358,6 +358,18 @@
return willValidate() && m_inputType->stepMismatch(value());
}
+bool HTMLInputElement::isValid() const
+{
+ if (!willValidate())
+ return true;
+
+ String value = this->value();
+ bool someError = m_inputType->typeMismatch() || m_inputType->stepMismatch(value) || m_inputType->rangeUnderflow(value) || m_inputType->rangeOverflow(value)
+ || tooShort(value, CheckDirtyFlag) || tooLong(value, CheckDirtyFlag) || m_inputType->patternMismatch(value) || m_inputType->valueMissing(value)
+ || m_inputType->hasBadInput() || customError();
+ return !someError;
+}
+
bool HTMLInputElement::getAllowedValueStep(Decimal* step) const
{
return m_inputType->getAllowedValueStep(step);
@@ -979,7 +991,7 @@
if (!value.isNull())
return value;
- AtomicString valueString = attributeWithoutSynchronization(valueAttr);
+ auto& valueString = attributeWithoutSynchronization(valueAttr);
value = sanitizeValue(valueString);
if (!value.isNull())
return value;
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (208576 => 208577)
--- trunk/Source/WebCore/html/HTMLInputElement.h 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/html/HTMLInputElement.h 2016-11-11 04:32:41 UTC (rev 208577)
@@ -71,6 +71,7 @@
bool tooLong() const final;
bool typeMismatch() const final;
bool valueMissing() const final;
+ bool isValid() const final;
WEBCORE_EXPORT String validationMessage() const final;
// Returns the minimum value for type=date, number, or range. Don't call this for other types.
Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (208576 => 208577)
--- trunk/Source/WebCore/html/TextFieldInputType.cpp 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp 2016-11-11 04:32:41 UTC (rev 208577)
@@ -394,7 +394,7 @@
break;
}
}
- return string.left(newLength);
+ return newLength < string.length() ? string.left(newLength) : string;
}
static String autoFillButtonTypeToAccessibilityLabel(AutoFillButtonType autoFillButtonType)
Modified: trunk/Source/WebCore/html/ValidityState.idl (208576 => 208577)
--- trunk/Source/WebCore/html/ValidityState.idl 2016-11-11 04:15:41 UTC (rev 208576)
+++ trunk/Source/WebCore/html/ValidityState.idl 2016-11-11 04:32:41 UTC (rev 208577)
@@ -33,5 +33,5 @@
readonly attribute boolean stepMismatch;
readonly attribute boolean badInput;
readonly attribute boolean customError;
- readonly attribute boolean valid;
+ [ImplementedAs=isValid] readonly attribute boolean valid;
};