mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
LibJS: Add helpers to Cell::Visitor for visiting AK collections
This commit is contained in:
parent
5d89d3090e
commit
1a6d025793
Notes:
sideshowbarker
2024-07-17 06:40:35 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/1a6d025793 Pull-request: https://github.com/SerenityOS/serenity/pull/23971 Reviewed-by: https://github.com/trflynn89
1 changed files with 59 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2024, Andreas Kling <kling@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -9,6 +9,7 @@
|
|||
#include <AK/Badge.h>
|
||||
#include <AK/Format.h>
|
||||
#include <AK/Forward.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/Noncopyable.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibJS/Forward.h>
|
||||
|
@ -73,6 +74,63 @@ public:
|
|||
visit_impl(const_cast<RemoveConst<T>&>(*cell.ptr()));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void visit(ReadonlySpan<T> span)
|
||||
{
|
||||
for (auto& value : span)
|
||||
visit(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void visit(Span<T> span)
|
||||
{
|
||||
for (auto& value : span)
|
||||
visit(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void visit(Vector<T> const& vector)
|
||||
{
|
||||
for (auto& value : vector)
|
||||
visit(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void visit(HashTable<T> const& table)
|
||||
{
|
||||
for (auto& value : table)
|
||||
visit(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void visit(OrderedHashTable<T> const& table)
|
||||
{
|
||||
for (auto& value : table)
|
||||
visit(value);
|
||||
}
|
||||
|
||||
template<typename K, typename V, typename T>
|
||||
void visit(HashMap<K, V, T> const& map)
|
||||
{
|
||||
for (auto& it : map) {
|
||||
if constexpr (requires { visit(it.key); })
|
||||
visit(it.key);
|
||||
if constexpr (requires { visit(it.value); })
|
||||
visit(it.value);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename K, typename V, typename T>
|
||||
void visit(OrderedHashMap<K, V, T> const& map)
|
||||
{
|
||||
for (auto& it : map) {
|
||||
if constexpr (requires { visit(it.key); })
|
||||
visit(it.key);
|
||||
if constexpr (requires { visit(it.value); })
|
||||
visit(it.value);
|
||||
}
|
||||
}
|
||||
|
||||
void visit(Value value);
|
||||
|
||||
// Allow explicitly ignoring a GC-allocated member in a visit_edges implementation instead
|
||||
|
|
Loading…
Add table
Reference in a new issue