Files
ladybird/Libraries/LibJS/Bytecode/IdentifierTable.h
Andreas Kling 6751d348a7 LibJS: Account executable storage as external memory
Report outline storage retained by bytecode executables, table
objects, object property iterator cache data, and shared function
instance data. This includes bytecode vectors, cache arrays, source
maps, class blueprint elements, and binding metadata.
2026-05-07 10:03:09 +02:00

58 lines
1.5 KiB
C++

/*
* Copyright (c) 2021, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/DistinctNumeric.h>
#include <AK/Utf16FlyString.h>
#include <AK/Vector.h>
#include <LibJS/Runtime/ExternalMemory.h>
namespace JS::Bytecode {
struct IdentifierTableIndex {
static constexpr u32 invalid = 0xffffffffu;
bool is_valid() const { return value != invalid; }
u32 value { 0 };
};
class IdentifierTable {
AK_MAKE_NONMOVABLE(IdentifierTable);
AK_MAKE_NONCOPYABLE(IdentifierTable);
public:
IdentifierTable() = default;
IdentifierTableIndex insert(Utf16FlyString);
Utf16FlyString const& get(IdentifierTableIndex) const;
void dump() const;
bool is_empty() const { return m_identifiers.is_empty(); }
size_t external_memory_size() const { return vector_external_memory_size(m_identifiers); }
ReadonlySpan<Utf16FlyString const> identifiers() const { return m_identifiers; }
private:
Vector<Utf16FlyString> m_identifiers;
};
}
namespace AK {
template<>
struct SentinelOptionalTraits<JS::Bytecode::IdentifierTableIndex> {
static constexpr JS::Bytecode::IdentifierTableIndex sentinel_value() { return { JS::Bytecode::IdentifierTableIndex::invalid }; }
static constexpr bool is_sentinel(JS::Bytecode::IdentifierTableIndex const& value) { return !value.is_valid(); }
};
template<>
class Optional<JS::Bytecode::IdentifierTableIndex> : public SentinelOptional<JS::Bytecode::IdentifierTableIndex> {
public:
using SentinelOptional::SentinelOptional;
};
}