ladybird/Libraries/LibJS/Runtime/CompletionCell.h
Andreas Kling a0bb31f7a0 LibJS: Make async functions & generators faster with helper types
Instead of returning internal generator results as ordinary JS::Objects
with properties, we now use GeneratorResult and CompletionCell which
both inherit from Cell directly and allow efficient access to state.

1.59x speedup on JetStream3/lazy-collections.js :^)
2025-04-01 02:30:42 +02:00

36 lines
782 B
C++

/*
* Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGC/CellAllocator.h>
#include <LibJS/Heap/Cell.h>
#include <LibJS/Runtime/Completion.h>
namespace JS {
class CompletionCell final : public Cell {
GC_CELL(CompletionCell, Cell);
GC_DECLARE_ALLOCATOR(CompletionCell);
public:
CompletionCell(Completion completion)
: m_completion(move(completion))
{
}
virtual ~CompletionCell() override;
[[nodiscard]] Completion const& completion() const { return m_completion; }
void set_completion(Completion completion) { m_completion = move(completion); }
private:
virtual void visit_edges(Cell::Visitor& visitor) override;
Completion m_completion;
};
}