Bug 1390342 - Skip pattern matching in HasPatternMismatch() if @pattern is not set. r=ehsan

We use a bitfield in HTMLInputElement to cache whether the input element has the
@pattern set, and skip pattern mathching in HasPatternMismatch() if the
attribute is not set.
This commit is contained in:
Jessica Jong
2017-08-17 23:57:00 -04:00
parent 6b9125b7d9
commit c991e197b3
3 changed files with 21 additions and 3 deletions

View File

@@ -1149,6 +1149,7 @@ HTMLInputElement::HTMLInputElement(already_AddRefed<mozilla::dom::NodeInfo>& aNo
, mPickerRunning(false)
, mSelectionCached(true)
, mIsPreviewEnabled(false)
, mHasPatternAttribute(false)
{
// If size is above 512, mozjemalloc allocates 1kB, see
// memory/mozjemalloc/jemalloc.c
@@ -1457,8 +1458,15 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
UpdateTooLongValidityState();
} else if (aName == nsGkAtoms::minlength) {
UpdateTooShortValidityState();
} else if (aName == nsGkAtoms::pattern && mDoneCreating) {
UpdatePatternMismatchValidityState();
} else if (aName == nsGkAtoms::pattern) {
// Although pattern attribute only applies to single line text controls,
// we set this flag for all input types to save having to check the type
// here.
mHasPatternAttribute = !!aValue;
if (mDoneCreating) {
UpdatePatternMismatchValidityState();
}
} else if (aName == nsGkAtoms::multiple) {
UpdateTypeMismatchValidityState();
} else if (aName == nsGkAtoms::max) {