From 4050c32dab1bc750654be0dbf08c942c4227e1cd Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 10 Jun 2026 12:34:28 +0100 Subject: [PATCH] Everywhere: Make use of Badge with multiple or derived types Now that Badge can have multiple types, and a Badge of a derived class can convert into a Badge of the superclass, we can simplify a few method signatures and overloads. --- AK/BufferedStream.h | 5 +---- AK/StringBase.h | 10 +++------- AK/StringBuilder.h | 6 ++++-- Libraries/LibCore/Socket.h | 4 +--- Libraries/LibWeb/CSS/Parser/Token.cpp | 8 +------- Libraries/LibWeb/CSS/Parser/Token.h | 3 +-- Libraries/LibWeb/DOM/Document.h | 3 +-- Libraries/LibWeb/DOM/Element.h | 3 +-- Libraries/LibWeb/DOM/Node.cpp | 7 +------ Libraries/LibWeb/DOM/Node.h | 3 +-- Libraries/LibWeb/HTML/HTMLScriptElement.h | 12 ++++-------- 11 files changed, 19 insertions(+), 45 deletions(-) diff --git a/AK/BufferedStream.h b/AK/BufferedStream.h index 9475b3b23e..4a55d49dfd 100644 --- a/AK/BufferedStream.h +++ b/AK/BufferedStream.h @@ -13,8 +13,6 @@ namespace AK { -template -concept StreamLike = IsBaseOf; template concept SeekableStreamLike = IsBaseOf; @@ -24,8 +22,7 @@ class BufferedHelper { AK_MAKE_DEFAULT_MOVABLE(BufferedHelper); public: - template - BufferedHelper(Badge, NonnullOwnPtr stream, CircularBuffer buffer) + BufferedHelper(Badge, NonnullOwnPtr stream, CircularBuffer buffer) : m_stream(move(stream)) , m_buffer(move(buffer)) { diff --git a/AK/StringBase.h b/AK/StringBase.h index bf5d48b33e..b6b34dd074 100644 --- a/AK/StringBase.h +++ b/AK/StringBase.h @@ -84,17 +84,13 @@ public: [[nodiscard]] bool operator==(StringBase const&) const; - [[nodiscard]] ALWAYS_INLINE constexpr FlatPtr raw(Badge) const { return bit_cast(m_impl); } - [[nodiscard]] ALWAYS_INLINE constexpr FlatPtr raw(Badge) const { return bit_cast(m_impl); } - - template - ALWAYS_INLINE ErrorOr replace_with_new_string(Badge, size_t byte_count, Func&& callback) + [[nodiscard]] ALWAYS_INLINE constexpr FlatPtr raw(Badge) const { - return replace_with_new_string(byte_count, forward(callback)); + return bit_cast(m_impl); } template - ALWAYS_INLINE ErrorOr replace_with_new_string(Badge, size_t byte_count, Func&& callback) + ALWAYS_INLINE ErrorOr replace_with_new_string(Badge, size_t byte_count, Func&& callback) { return replace_with_new_string(byte_count, forward(callback)); } diff --git a/AK/StringBuilder.h b/AK/StringBuilder.h index 39e68eee5d..feefe6102e 100644 --- a/AK/StringBuilder.h +++ b/AK/StringBuilder.h @@ -170,8 +170,10 @@ public: return {}; } - Optional leak_buffer_for_string_construction(Badge) { return leak_buffer_for_string_construction(); } - Optional leak_buffer_for_string_construction(Badge) { return leak_buffer_for_string_construction(); } + Optional leak_buffer_for_string_construction(Badge) + { + return leak_buffer_for_string_construction(); + } private: void initialize_buffer(Mode, size_t capacity); diff --git a/Libraries/LibCore/Socket.h b/Libraries/LibCore/Socket.h index 08ba9c224e..1a47d72d50 100644 --- a/Libraries/LibCore/Socket.h +++ b/Libraries/LibCore/Socket.h @@ -120,9 +120,7 @@ class CORE_API PosixSocketHelper { AK_MAKE_NONCOPYABLE(PosixSocketHelper); public: - template - PosixSocketHelper(Badge) - requires(IsBaseOf) + PosixSocketHelper(Badge) { } diff --git a/Libraries/LibWeb/CSS/Parser/Token.cpp b/Libraries/LibWeb/CSS/Parser/Token.cpp index 97b949f729..54827ab3e7 100644 --- a/Libraries/LibWeb/CSS/Parser/Token.cpp +++ b/Libraries/LibWeb/CSS/Parser/Token.cpp @@ -418,13 +418,7 @@ StringView Token::bracket_mirror_string() const return ""sv; } -void Token::set_position_range(Badge, SourcePosition start, SourcePosition end) -{ - m_start_position = start; - m_end_position = end; -} - -void Token::set_position_range(Badge, SourcePosition start, SourcePosition end) +void Token::set_position_range(Badge, SourcePosition start, SourcePosition end) { m_start_position = start; m_end_position = end; diff --git a/Libraries/LibWeb/CSS/Parser/Token.h b/Libraries/LibWeb/CSS/Parser/Token.h index 593fac4483..595720686e 100644 --- a/Libraries/LibWeb/CSS/Parser/Token.h +++ b/Libraries/LibWeb/CSS/Parser/Token.h @@ -182,8 +182,7 @@ public: String const& original_source_text() const { return m_original_source_text; } SourcePosition const& start_position() const { return m_start_position; } SourcePosition const& end_position() const { return m_end_position; } - void set_position_range(Badge, SourcePosition start, SourcePosition end); - void set_position_range(Badge, SourcePosition start, SourcePosition end); + void set_position_range(Badge, SourcePosition start, SourcePosition end); bool operator==(Token const& other) const { diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index da2cb6d5f0..0e5417846a 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -994,8 +994,7 @@ public: GC::Ptr navigable() const; void set_navigable(GC::Ptr); - template T> - void set_needs_repaint(Badge, InvalidateDisplayList should_invalidate_display_list = InvalidateDisplayList::Yes) + void set_needs_repaint(Badge, InvalidateDisplayList should_invalidate_display_list = InvalidateDisplayList::Yes) { set_needs_repaint(should_invalidate_display_list); } diff --git a/Libraries/LibWeb/DOM/Element.h b/Libraries/LibWeb/DOM/Element.h index aa20d32772..eca3d12b24 100644 --- a/Libraries/LibWeb/DOM/Element.h +++ b/Libraries/LibWeb/DOM/Element.h @@ -388,8 +388,7 @@ public: Layout::NodeWithStyle* pseudo_element_unsafe_layout_node(CSS::PseudoElement) const; bool has_synthetic_pseudo_elements() const; - template T> - void clear_synthetic_pseudo_element_layout_nodes(Badge) { clear_synthetic_pseudo_element_layout_nodes(); } + void clear_synthetic_pseudo_element_layout_nodes(Badge) { clear_synthetic_pseudo_element_layout_nodes(); } void serialize_children_as_json(JsonObjectSerializer&) const; diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index e5ac7f714a..3076004541 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -1527,12 +1527,7 @@ WebIDL::ExceptionOr> Node::clone_node_binding(bool subtree) return clone_node(nullptr, subtree); } -void Node::set_document(Badge, Document& document) -{ - set_document(document); -} - -void Node::set_document(Badge, Document& document) +void Node::set_document(Badge, Document& document) { set_document(document); } diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index d5a542c57e..657409f5aa 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -378,8 +378,7 @@ public: CSS::StyleScope const& style_scope() const { return const_cast(this)->style_scope(); } void for_each_style_scope_which_may_observe_the_node(Function const&); - void set_document(Badge, Document&); - void set_document(Badge, Document&); + void set_document(Badge, Document&); virtual EventTarget* get_parent(Event const&) override; diff --git a/Libraries/LibWeb/HTML/HTMLScriptElement.h b/Libraries/LibWeb/HTML/HTMLScriptElement.h index dcbfbfe51e..73b37bd335 100644 --- a/Libraries/LibWeb/HTML/HTMLScriptElement.h +++ b/Libraries/LibWeb/HTML/HTMLScriptElement.h @@ -29,17 +29,13 @@ public: bool is_ready_to_be_parser_executed() const { return m_ready_to_be_parser_executed; } bool failed_to_load() const { return m_failed_to_load; } - template T> - void set_parser_document(Badge, DOM::Document& document) { m_parser_document = &document; } + void set_parser_document(Badge, DOM::Document& document) { m_parser_document = &document; } - template T> - void set_force_async(Badge, bool b) { m_force_async = b; } + void set_force_async(Badge, bool b) { m_force_async = b; } - template T> - void set_already_started(Badge, bool b) { m_already_started = b; } + void set_already_started(Badge, bool b) { m_already_started = b; } - template T> - void prepare_script(Badge) { prepare_script(); } + void prepare_script(Badge) { prepare_script(); } void execute_script();