From 1a99cc4a14e00eef63a70a071940221d2957633f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 16 Mar 2022 07:46:17 -0400 Subject: [PATCH] LibWeb: Use the cached HTMLInputElement type within associated getters --- .../LibWeb/HTML/HTMLInputElement.cpp | 31 ++++--------------- .../Libraries/LibWeb/HTML/HTMLInputElement.h | 2 +- 2 files changed, 7 insertions(+), 26 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp index abd9f8bebf..f3f6265663 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -239,34 +239,15 @@ void HTMLInputElement::did_remove_attribute(FlyString const& name) String HTMLInputElement::type() const { - auto value = attribute(HTML::AttributeNames::type); - -#define __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(keyword, _) \ - if (value.equals_ignoring_case(#keyword)) \ - return #keyword; - ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTES -#undef __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE - - // The missing value default and the invalid value default are the Text state. - // https://html.spec.whatwg.org/multipage/input.html#the-input-element:missing-value-default - // https://html.spec.whatwg.org/multipage/input.html#the-input-element:invalid-value-default - return "text"; -} - -HTMLInputElement::TypeAttributeState HTMLInputElement::type_state() const -{ - auto value = attribute(HTML::AttributeNames::type); - + switch (m_type) { #define __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE(keyword, state) \ - if (value.equals_ignoring_case(#keyword)) \ - return HTMLInputElement::TypeAttributeState::state; - ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTES + case TypeAttributeState::state: \ + return #keyword##sv; + ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTES #undef __ENUMERATE_HTML_INPUT_TYPE_ATTRIBUTE + } - // The missing value default and the invalid value default are the Text state. - // https://html.spec.whatwg.org/multipage/input.html#the-input-element:missing-value-default - // https://html.spec.whatwg.org/multipage/input.html#the-input-element:invalid-value-default - return HTMLInputElement::TypeAttributeState::Text; + VERIFY_NOT_REACHED(); } void HTMLInputElement::set_type(String const& type) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h index 80e50e79a7..78935804b6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -53,7 +53,7 @@ public: }; String type() const; - TypeAttributeState type_state() const; + TypeAttributeState type_state() const { return m_type; } void set_type(String const&); String default_value() const { return attribute(HTML::AttributeNames::value); }