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.
This commit is contained in:
Sam Atkins 2026-06-10 12:34:28 +01:00 committed by Jelle Raaijmakers
parent 071b4f7062
commit 4050c32dab
11 changed files with 19 additions and 45 deletions

View file

@ -13,8 +13,6 @@
namespace AK {
template<typename T>
concept StreamLike = IsBaseOf<Stream, T>;
template<typename T>
concept SeekableStreamLike = IsBaseOf<SeekableStream, T>;
@ -24,8 +22,7 @@ class BufferedHelper {
AK_MAKE_DEFAULT_MOVABLE(BufferedHelper);
public:
template<StreamLike U>
BufferedHelper(Badge<U>, NonnullOwnPtr<T> stream, CircularBuffer buffer)
BufferedHelper(Badge<Stream>, NonnullOwnPtr<T> stream, CircularBuffer buffer)
: m_stream(move(stream))
, m_buffer(move(buffer))
{

View file

@ -84,17 +84,13 @@ public:
[[nodiscard]] bool operator==(StringBase const&) const;
[[nodiscard]] ALWAYS_INLINE constexpr FlatPtr raw(Badge<FlyString>) const { return bit_cast<FlatPtr>(m_impl); }
[[nodiscard]] ALWAYS_INLINE constexpr FlatPtr raw(Badge<String>) const { return bit_cast<FlatPtr>(m_impl); }
template<typename Func>
ALWAYS_INLINE ErrorOr<void> replace_with_new_string(Badge<StringView>, size_t byte_count, Func&& callback)
[[nodiscard]] ALWAYS_INLINE constexpr FlatPtr raw(Badge<FlyString, String>) const
{
return replace_with_new_string(byte_count, forward<Func>(callback));
return bit_cast<FlatPtr>(m_impl);
}
template<typename Func>
ALWAYS_INLINE ErrorOr<void> replace_with_new_string(Badge<Utf16View>, size_t byte_count, Func&& callback)
ALWAYS_INLINE ErrorOr<void> replace_with_new_string(Badge<StringView, Utf16View>, size_t byte_count, Func&& callback)
{
return replace_with_new_string(byte_count, forward<Func>(callback));
}

View file

@ -170,8 +170,10 @@ public:
return {};
}
Optional<Buffer::OutlineBuffer> leak_buffer_for_string_construction(Badge<Detail::StringData>) { return leak_buffer_for_string_construction(); }
Optional<Buffer::OutlineBuffer> leak_buffer_for_string_construction(Badge<Detail::Utf16StringData>) { return leak_buffer_for_string_construction(); }
Optional<Buffer::OutlineBuffer> leak_buffer_for_string_construction(Badge<Detail::StringData, Detail::Utf16StringData>)
{
return leak_buffer_for_string_construction();
}
private:
void initialize_buffer(Mode, size_t capacity);

View file

@ -120,9 +120,7 @@ class CORE_API PosixSocketHelper {
AK_MAKE_NONCOPYABLE(PosixSocketHelper);
public:
template<typename T>
PosixSocketHelper(Badge<T>)
requires(IsBaseOf<Socket, T>)
PosixSocketHelper(Badge<Socket>)
{
}

View file

@ -418,13 +418,7 @@ StringView Token::bracket_mirror_string() const
return ""sv;
}
void Token::set_position_range(Badge<Tokenizer>, SourcePosition start, SourcePosition end)
{
m_start_position = start;
m_end_position = end;
}
void Token::set_position_range(Badge<RustTokenizer>, SourcePosition start, SourcePosition end)
void Token::set_position_range(Badge<Tokenizer, RustTokenizer>, SourcePosition start, SourcePosition end)
{
m_start_position = start;
m_end_position = end;

View file

@ -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<Tokenizer>, SourcePosition start, SourcePosition end);
void set_position_range(Badge<RustTokenizer>, SourcePosition start, SourcePosition end);
void set_position_range(Badge<Tokenizer, RustTokenizer>, SourcePosition start, SourcePosition end);
bool operator==(Token const& other) const
{

View file

@ -994,8 +994,7 @@ public:
GC::Ptr<HTML::Navigable> navigable() const;
void set_navigable(GC::Ptr<HTML::Navigable>);
template<OneOf<Node, Painting::Paintable, HTML::Navigable, CSS::VisualViewport, Web::EventHandler> T>
void set_needs_repaint(Badge<T>, InvalidateDisplayList should_invalidate_display_list = InvalidateDisplayList::Yes)
void set_needs_repaint(Badge<Node, Painting::Paintable, HTML::Navigable, CSS::VisualViewport, Web::EventHandler>, InvalidateDisplayList should_invalidate_display_list = InvalidateDisplayList::Yes)
{
set_needs_repaint(should_invalidate_display_list);
}

View file

@ -388,8 +388,7 @@ public:
Layout::NodeWithStyle* pseudo_element_unsafe_layout_node(CSS::PseudoElement) const;
bool has_synthetic_pseudo_elements() const;
template<OneOf<Layout::TreeBuilder, Document, Node> T>
void clear_synthetic_pseudo_element_layout_nodes(Badge<T>) { clear_synthetic_pseudo_element_layout_nodes(); }
void clear_synthetic_pseudo_element_layout_nodes(Badge<Layout::TreeBuilder, Node>) { clear_synthetic_pseudo_element_layout_nodes(); }
void serialize_children_as_json(JsonObjectSerializer<StringBuilder>&) const;

View file

@ -1527,12 +1527,7 @@ WebIDL::ExceptionOr<GC::Ref<Node>> Node::clone_node_binding(bool subtree)
return clone_node(nullptr, subtree);
}
void Node::set_document(Badge<Document>, Document& document)
{
set_document(document);
}
void Node::set_document(Badge<NamedNodeMap>, Document& document)
void Node::set_document(Badge<Document, NamedNodeMap>, Document& document)
{
set_document(document);
}

View file

@ -378,8 +378,7 @@ public:
CSS::StyleScope const& style_scope() const { return const_cast<Node*>(this)->style_scope(); }
void for_each_style_scope_which_may_observe_the_node(Function<void(CSS::StyleScope&)> const&);
void set_document(Badge<Document>, Document&);
void set_document(Badge<NamedNodeMap>, Document&);
void set_document(Badge<Document, NamedNodeMap>, Document&);
virtual EventTarget* get_parent(Event const&) override;

View file

@ -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<OneOf<XMLDocumentBuilder, HTMLParser> T>
void set_parser_document(Badge<T>, DOM::Document& document) { m_parser_document = &document; }
void set_parser_document(Badge<XMLDocumentBuilder, HTMLParser>, DOM::Document& document) { m_parser_document = &document; }
template<OneOf<XMLDocumentBuilder, HTMLParser> T>
void set_force_async(Badge<T>, bool b) { m_force_async = b; }
void set_force_async(Badge<XMLDocumentBuilder, HTMLParser>, bool b) { m_force_async = b; }
template<OneOf<XMLDocumentBuilder, HTMLParser> T>
void set_already_started(Badge<T>, bool b) { m_already_started = b; }
void set_already_started(Badge<XMLDocumentBuilder, HTMLParser>, bool b) { m_already_started = b; }
template<OneOf<XMLDocumentBuilder, HTMLParser> T>
void prepare_script(Badge<T>) { prepare_script(); }
void prepare_script(Badge<XMLDocumentBuilder, HTMLParser>) { prepare_script(); }
void execute_script();