From 75e7c2c5c052a4cbf6b33796b555776d9c64168f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 28 Oct 2021 12:01:15 +0100 Subject: [PATCH] LibWeb: Convert CSS Token::m_unit from StringBuilder to FlyString This value doesn't change once it's assigned to the Token, so it can be more lightweight than a StringBuilder. --- Userland/Libraries/LibWeb/CSS/Parser/Token.cpp | 6 +++--- Userland/Libraries/LibWeb/CSS/Parser/Token.h | 5 +++-- Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp index 8ec29257dd..9eb7c68186 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Token.cpp @@ -59,12 +59,12 @@ String Token::to_debug_string() const case Type::Percentage: builder.append("Percentage: "); builder.append(m_value.to_string()); - builder.append(m_unit.to_string()); + builder.append('%'); return builder.to_string(); case Type::Dimension: builder.append("Dimension: "); builder.append(m_value.to_string()); - builder.append(m_unit.to_string()); + builder.append(m_unit); return builder.to_string(); case Type::Whitespace: builder.append("Whitespace"); @@ -140,7 +140,7 @@ String Token::to_debug_string() const } builder.append("', unit: '"); - builder.append(m_unit.to_string()); + builder.append(m_unit); } builder.append("' }"); diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Token.h b/Userland/Libraries/LibWeb/CSS/Parser/Token.h index 9289aa122f..e42e0ee378 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Token.h +++ b/Userland/Libraries/LibWeb/CSS/Parser/Token.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include #include @@ -132,7 +133,7 @@ public: StringView dimension_unit() const { VERIFY(m_type == Type::Dimension); - return m_unit.string_view(); + return m_unit.view(); } double dimension_value() const { @@ -175,7 +176,7 @@ private: Type m_type { Type::Invalid }; StringBuilder m_value; - StringBuilder m_unit; + FlyString m_unit; HashType m_hash_type { HashType::Unrestricted }; NumberType m_number_type { NumberType::Integer }; double m_number_value { 0 }; diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp index c139e9fbf5..269c572213 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Tokenizer.cpp @@ -685,7 +685,7 @@ Token Tokenizer::consume_a_numeric_token() auto unit = consume_a_name(); VERIFY(!unit.is_empty() && !unit.is_whitespace()); - token.m_unit.append(unit); + token.m_unit = move(unit); return token; }