ladybird/Libraries/LibJS/Runtime/NumberObject.h
Andreas Kling c12f8b80dc LibJS: Add fast_is<T> helpers for all the primitive wrapper objects
The JS runtime is full of checks for is<NumberObject> and friends.
They were showing up in a Speedometer profile as ~1% spent in
dynamic_cast, and this basically chops that down to nothing.
2025-03-25 23:57:00 +00:00

36 lines
711 B
C++

/*
* Copyright (c) 2020, Andreas Kling <andreas@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/Object.h>
namespace JS {
class NumberObject : public Object {
JS_OBJECT(NumberObject, Object);
GC_DECLARE_ALLOCATOR(NumberObject);
public:
static GC::Ref<NumberObject> create(Realm&, double);
virtual ~NumberObject() override = default;
double number() const { return m_value; }
protected:
NumberObject(double, Object& prototype);
private:
virtual bool is_number_object() const final { return true; }
double m_value { 0 };
};
template<>
inline bool Object::fast_is<NumberObject>() const { return is_number_object(); }
}