mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-08 13:37:10 +09:00

- Avoids unnecessary conversions between StringOrSymbol and PropertyKey on the hot path of property access. - Simplifies the code by removing StringOrSymbol and using PropertyKey directly. There was no reason to have a separate StringOrSymbol type representing the same data as PropertyKey, just with the index key stored as a string. PropertyKey has been updated to use a tagged pointer instead of a Variant, so it still occupies 8 bytes, same as StringOrSymbol. 12% improvement on JetStream/gcc-loops.cpp.js 12% improvement on MicroBench/object-assign.js 7% improvement on MicroBench/object-keys.js
38 lines
852 B
C++
38 lines
852 B
C++
/*
|
|
* Copyright (c) 2020, Matthew Olsson <mattco@serenityos.org>
|
|
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/String.h>
|
|
#include <LibGC/CellAllocator.h>
|
|
#include <LibJS/Heap/Cell.h>
|
|
|
|
namespace JS {
|
|
|
|
class Symbol final : public Cell {
|
|
GC_CELL(Symbol, Cell);
|
|
GC_DECLARE_ALLOCATOR(Symbol);
|
|
|
|
public:
|
|
[[nodiscard]] static GC::Ref<Symbol> create(VM&, Optional<String> description, bool is_global);
|
|
|
|
virtual ~Symbol() = default;
|
|
|
|
Optional<String> const& description() const { return m_description; }
|
|
bool is_global() const { return m_is_global; }
|
|
|
|
ErrorOr<String> descriptive_string() const;
|
|
Optional<String> key() const;
|
|
|
|
private:
|
|
Symbol(Optional<String>, bool);
|
|
|
|
Optional<String> m_description;
|
|
bool m_is_global;
|
|
};
|
|
|
|
}
|